There are no attributes in Ruby. When you use attr_reader :imavar, you create a method to retrieve the value:
def imavar
@imavar
end
So, to create an alias for a variable, you can create an alias for the method:
alias_method :hesavar, :imavar
Full example:
class DataHolder
attr_reader :imavar
alias_method :hesavar, :imavar
def initialize(value)
@imavar = value
end
end
d = DataHolder.new(42)
d.imavar
=> 42
d.hesavar
=> 42
source
share