@ -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) }
def to_s = name
def call(interpreter, args)
@ -470,6 +470,20 @@ class TestInterpreter < Lox::Test
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
private
def assert_interpreted(expected, src)