Class: Baba::BabaClass
Direct Known Subclasses
Instance Attribute Summary collapse
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#superclass ⇒ Object
readonly
Returns the value of attribute superclass.
Instance Method Summary collapse
- #arity ⇒ Object
- #call(interpreter, arguments) ⇒ Object
- #find_method(method) ⇒ Object
-
#initialize(name, superclass, methods) ⇒ BabaClass
constructor
A new instance of BabaClass.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, superclass, methods) ⇒ BabaClass
Returns a new instance of BabaClass.
8 9 10 11 12 |
# File 'lib/baba/class.rb', line 8 def initialize(name, superclass, methods) @name = name @methods = methods @superclass = superclass end |
Instance Attribute Details
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
6 7 8 |
# File 'lib/baba/class.rb', line 6 def methods @methods end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/baba/class.rb', line 6 def name @name end |
#superclass ⇒ Object (readonly)
Returns the value of attribute superclass.
6 7 8 |
# File 'lib/baba/class.rb', line 6 def superclass @superclass end |
Instance Method Details
#arity ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/baba/class.rb', line 24 def arity initializer = find_method("init") unless initializer.nil? initializer.arity else 0 end end |
#call(interpreter, arguments) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/baba/class.rb', line 14 def call(interpreter, arguments) instance = Instance.new(self) initializer = find_method("init") unless initializer.nil? initializer.bind(instance).call(interpreter, arguments) end return instance end |
#find_method(method) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/baba/class.rb', line 33 def find_method(method) if @methods.include?(method) return @methods[method] end unless @superclass.nil? return superclass.find_method(method) end end |
#inspect ⇒ Object
47 48 49 |
# File 'lib/baba/class.rb', line 47 def inspect "<#{@name} < #{superclass.inspect} : #{@methods.inspect}>" end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/baba/class.rb', line 43 def to_s "<#{@name}>" end |