Excuse me for my example; I am trying to develop an independent example to present my requirement, it may appear too contrived:
class Animal
NAME = 'no name'
%w(bark walk).each do |action|
define_method(action) do
NAME + ' ' + action
end
end
end
class Pig < Animal
NAME = 'piggie'
end
Animal.new.walk # => "no name walk"
Pig.new.walk # => "no name walk"
The last line is expected to return "piggie walk"
, but it doesn't. Why does that happen and how to make it use the constant defined in Pig
?