Re-enable spec/library for full CI runs.
[rbx.git] / kernel / core / block_context.rb
blobcda0907ba6675d6f1757d614095297ec744b5ac7
1 # depends on: method_context.rb block_environment.rb
3 ##
4 # Stores all information about a running BlockEnvironment.
6 # A BlockContext contains a home and a BlockEnvironment in addition to a
7 # MethodContext.  The home points to the MethodContext that encloses the
8 # block which is used to find self, etc.
10 class BlockContext < MethodContext
12   def from_eval?
13     self.env.from_eval?
14   end
16   def last_match
17     home.last_match
18   end
20   def last_match=(match)
21     home.last_match = match
22   end
24   def nth_ref(idx)
25     home.nth_ref(idx)
26   end
28   def back_ref(idx)
29     home.back_ref(idx)
30   end
32   def method_scope
33     @method_scope || env.home_block.method_scope
34   end
36   ##
37   # Active context (instance of MethodContext) that started
38   # execution of this block context.
40   def home
41     env.home
42   end
44   ##
45   # Name of home method.
47   def name
48     home.name
49   end
51   ##
52   # Block context has no receiver thus uses receiver from it's home method
53   # context.
55   def receiver
56     home.receiver
57   end
59   ##
60   # Block context has no own module thus uses module from it's home method
61   # context.
63   def method_module
64     home.method_module
65   end
67   ##
68   # Static scope of home method context.
70   def current_scope
71     if ss = method.staticscope
72       return ss.module
73     else
74       home.current_scope
75     end
76   end
78   ##
79   # instance_eval needs alternate const behavior
81   def __const_set__(name, value)
82     const_scope = env.constant_scope.module
83     const_scope.__send__(:__const_set__, name, value)
84   end
85 end