Sha256: 7078f10d53a5f4aa6ca5c9da05aecef28a7a4837dc1234185cc798eef477f6bd

Contents?: true

Size: 623 Bytes

Versions: 3

Compression:

Stored size: 623 Bytes

Contents

# TITLE:
#
#   Binding Variables
#
# SUMMARY:
#
#   Access binding variables. This requires the #eval.

require 'facets/binding/eval.rb'

#
class Binding

  # Returns the local variables defined in the binding context
  #
  #   a = 2
  #   binding.local_variables  #=> ["a"]
  #
  def local_variables()
    eval("local_variables")
  end

  # Returns the value of some variable.
  #
  #   a = 2
  #   binding["a"]  #=> 2
  #
  def []( x )
    eval( x.to_s )
  end

  # Set the value of a local variable.
  #
  #   binding["a"] = 4
  #   a  #=> 4
  #
  def []=( l, v )
    eval( "lambda {|v| #{l} = v}").call( v )
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-2.2.0 lib/core/facets/binding/vars.rb
facets-2.2.1 lib/core/facets/binding/vars.rb
facets-2.3.0 lib/core/facets/binding/vars.rb