12.7
change ovslyxyqmnzorspqovkmzwtzunqkyrqy
commit 3b14602d0a1c4f5951bfa1413284816848778588
author Alpha Chen <alpha@kejadlen.dev>
date
parent rntmpqsp
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