Aliasing methods in Ruby is relatively straight-forward. A contrived example:
class Person
def name
puts "Roger"
end
end
class User < Person
alias :old_name :name
def name
old_name
puts "Staubach"
end
end
In this case, running User.new.name
will output:
Roger
Staubach
That works as expected. However, I'm trying to alias a setter method, which is apparently not straight-forward:
class Person
def name=(whatever)
puts whatever
end
end
class User < Person
alias :old_name= :name=
def name=(whatever)
puts whatever
old_name = whatever
end
end
With this, calling User.new.name = "Roger"
will output:
Roger
It appears that the new aliased method gets called, but the original does not.
What is up with that?
ps - I know about super
and let's just say for the sake of brevity that I do not want to use it here