diff --git a/ruby/lib/lox/lox_class.rb b/ruby/lib/lox/lox_class.rb
index 274adc8..362299d 100644
--- a/ruby/lib/lox/lox_class.rb
+++ b/ruby/lib/lox/lox_class.rb
@@ -9,7 +9,10 @@ module Lox
@name, @superclass, @methods = name, superclass, methods
end
- def find_method(name) = @methods[name]
+ def find_method(name)
+ @methods.fetch(name) { @superclass&.find_method(name) }
+ end
+
def to_s = name
def call(interpreter, args)
diff --git a/ruby/test/lox/test_interpreter.rb b/ruby/test/lox/test_interpreter.rb
index 682afc9..5410fbc 100644
--- a/ruby/test/lox/test_interpreter.rb
+++ b/ruby/test/lox/test_interpreter.rb
@@ -470,6 +470,20 @@ class TestInterpreter < Lox::Test
end
end
+ def test_inheriting_methods
+ assert_interpreted "Fry until golden brown.", <<~SRC
+ class Doughnut {
+ cook() {
+ print "Fry until golden brown.";
+ }
+ }
+
+ class BostonCream < Doughnut {}
+
+ BostonCream().cook();
+ SRC
+ end
+
private
def assert_interpreted(expected, src)