Is there a way to include a module in a class so that module methods override class methods? For instance:
module UpcasedName def name @name.upcase end end class User attr_accessor :name include UpcasedName end u = User.new u.name = 'john' puts u.name
In the above example, u.name is "john" and not "JOHN". I know that if I expand the user object and not include the module in the class, this will work
module UpcasedName def name @name.upcase end end class User attr_accessor :name end u = User.new u.name = 'john' u.extend UpcasedName puts u.name
However, I want to enable the module at the class level, not at the object level.
source share