Alpha Chen 2 years ago
parent 6a9ef7dde1
commit 59f286c139

@ -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)

@ -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)

Loading…
Cancel
Save