Class: ToyLangClass
Instance Attribute Summary collapse
#ruby_value, #runtime_class
Instance Method Summary
collapse
#call
Constructor Details
#initialize(superclass = nil) ⇒ ToyLangClass
Returns a new instance of ToyLangClass.
6
7
8
9
10
11
|
# File 'lib/toylang/runtime/class.rb', line 6
def initialize(superclass = nil)
@runtime_methods = {}
@runtime_class = Runtime['Class'] if defined?(Runtime)
@runtime_superclass = superclass
super(runtime_class)
end
|
Instance Attribute Details
#runtime_methods ⇒ Object
Returns the value of attribute runtime_methods.
4
5
6
|
# File 'lib/toylang/runtime/class.rb', line 4
def runtime_methods
@runtime_methods
end
|
Instance Method Details
#def(name, &block) ⇒ Object
24
25
26
|
# File 'lib/toylang/runtime/class.rb', line 24
def def(name, &block)
@runtime_methods[name.to_s] = block
end
|
#inspect ⇒ Object
36
37
38
|
# File 'lib/toylang/runtime/class.rb', line 36
def inspect
"#<ToyLangClass class=#{@runtime_class} superclass=#{@runtime_superclass}"
end
|
#lookup(method_name) ⇒ Object
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/toylang/runtime/class.rb', line 13
def lookup(method_name)
method = @runtime_methods[method_name]
unless method
return @runtime_superclass.lookup(method_name) if @runtime_superclass
raise "Method not found: #{method_name}"
end
method
end
|
#new ⇒ Object
28
29
30
|
# File 'lib/toylang/runtime/class.rb', line 28
def new
ToyLangObject.new(self)
end
|
#new_with_value(value) ⇒ Object
32
33
34
|
# File 'lib/toylang/runtime/class.rb', line 32
def new_with_value(value)
ToyLangObject.new(self, value)
end
|