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

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

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -