Alias attr_reader in Ruby -


is possible alias attr_reader method in ruby? have class favourites property want alias favorites american users. what's idiomatic ruby way this?

attr_reader generates appropriate instance methods. this:

class foo   attr_reader :bar end 

is identical to:

class foo   def bar     @bar   end end 

therefore, alias_method works you'd expect to:

class foo   attr_reader :favourites   alias_method :favorites, :favourites    # , if need provide writers   attr_writer :favourites   alias_method :favorites=, :favourites= end 

Comments