I just did this experiment:
class A < Hash
def foo
'foo'
end
end
class A < Hash
def bar
'bar'
end
end
As long as I get the expected result, the second declaration extends the first. However, I was surprised by this:
class A
def call
puts foo
puts bar
end
end
The above code works, but only if I declare it later. Otherwise, I get:
TypeError: superclass mismatch for class A
Can I assume that it is safe in Ruby to skip a superclass specification without side effects after making sure that the original-first declaration has been parsed?
source
share