diff --git a/ruby/lib/lox/lox_class.rb b/ruby/lib/lox/lox_class.rb index 44a9f37..017ea86 100644 --- a/ruby/lib/lox/lox_class.rb +++ b/ruby/lib/lox/lox_class.rb @@ -11,8 +11,21 @@ module Lox def find_method(name) = @methods[name] def to_s = name - def call(interpreter, args) = Instance.new(self) - def arity = 0 + + def call(interpreter, args) + instance = Instance.new(self) + + if init = find_method("init") + init.bind(instance).call(interpreter, args) + end + + instance + end + + def arity + init = find_method("init") + init ? init.arity : 0 + end end end