What is the best way to create alias to attributes in Ruby?

后端 未结 3 1342
梦谈多话
梦谈多话 2021-01-17 08:12

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

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-17 09:01

    add

    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
    

提交回复
热议问题