What is the best way to create an alias to a instance atribute in Ruby (I\'m not using rails or any ruby gem, just, Ruby).
For example given the class below, how can I c
As John points out, you need to alias both the reader and the writer. This being Ruby, it's quite easy to define your own alias method to handle this for you.
class Module
def alias_attr(new_attr, original)
alias_method(new_attr, original) if method_defined? original
new_writer = "#{new_attr}="
original_writer = "#{original}="
alias_method(new_writer, original_writer) if method_defined? original_writer
end
end