Re-enable spec/library for full CI runs.
[rbx.git] / kernel / core / binding.rb
blobb08ebd5fd24639ee27dbec3a5b61fbe843b73453
1 ##
2 # Objects of class Binding encapsulate the execution context at some
3 # particular place in the code and retain this context for future use. The
4 # variables, methods, value of self, and possibly an iterator block that can
5 # be accessed in this context are all retained. Binding objects can be created
6 # using Kernel#binding, and are made available to the callback of
7 # Kernel#set_trace_func.
9 # These binding objects can be passed as the second argument of the
10 # Kernel#eval method, establishing an environment for the evaluation.
12 #   class Demo
13 #     def initialize(n)
14 #       @secret = n
15 #     end
16 #     def getBinding
17 #       return binding()
18 #     end
19 #   end
20 #   
21 #   k1 = Demo.new(99)
22 #   b1 = k1.getBinding
23 #   k2 = Demo.new(-3)
24 #   b2 = k2.getBinding
25 #   
26 #   eval("@secret", b1)   #=> 99
27 #   eval("@secret", b2)   #=> -3
28 #   eval("@secret")       #=> nil
30 # Binding objects have no class-specific methods.
32 class Binding
33   attr_accessor :context
34   attr_accessor :proc_environment
36   def from_proc?
37     @proc_environment
38   end
40   def self.setup(ctx)
41     bind = allocate()
42     
43     bind.context = ctx
44     return bind
45   end
46 end