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

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -