Ruby – the best way to create alias to attributes in Ruby


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 create an alias to the :student_name attribute accessors?

class Student
  attr_accessor :student_name
  alias :name :student_name    #wrong

s =
s.student_name = "Jordan"
puts  # --> Jordan = "Michael" # --> NoMethodError: undefined method `name=' for #<Student:0x572394> ...

Thank's guys!

Best Solution


alias :name :student_name    # not wrong, only for getter
alias :name= :student_name=  # add this for setter
alias :name? :student_name?  # add this for boolean