Take the 2008 Git User's Survey and help out! [ hide ]

public
Description: Rubinius, the Ruby VM
Homepage: http://rubini.us
Clone URL: git://github.com/evanphx/rubinius.git
Search Repo:
rubinius / kernel / core / block_context.rb
100644 85 lines (65 sloc) 1.509 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# depends on: method_context.rb block_environment.rb
 
##
# Stores all information about a running BlockEnvironment.
#
# A BlockContext contains a home and a BlockEnvironment in addition to a
# MethodContext. The home points to the MethodContext that encloses the
# block which is used to find self, etc.
 
class BlockContext < MethodContext
 
  def from_eval?
    self.env.from_eval?
  end
 
  def last_match
    home.last_match
  end
 
  def last_match=(match)
    home.last_match = match
  end
 
  def nth_ref(idx)
    home.nth_ref(idx)
  end
 
  def back_ref(idx)
    home.back_ref(idx)
  end
 
  def method_scope
    @method_scope || env.home_block.method_scope
  end
 
  ##
  # Active context (instance of MethodContext) that started
  # execution of this block context.
 
  def home
    env.home
  end
 
  ##
  # Name of home method.
 
  def name
    home.name
  end
 
  ##
  # Block context has no receiver thus uses receiver from it's home method
  # context.
 
  def receiver
    home.receiver
  end
 
  ##
  # Block context has no own module thus uses module from it's home method
  # context.
 
  def method_module
    home.method_module
  end
 
  ##
  # Static scope of home method context.
 
  def current_scope
    if ss = method.staticscope
      return ss.module
    else
      home.current_scope
    end
  end
 
  ##
  # instance_eval needs alternate const behavior
 
  def __const_set__(name, value)
    const_scope = env.constant_scope.module
    const_scope.__send__(:__const_set__, name, value)
  end
end