but it is kinda ugly. Then I realize that extend keyword exists, but it
is possible to extend only modules not classes. So this realy nice
example would work only if User is a module.
I don’t know if my tip applies for you (haven’t worked with neither
Rails nor Mongoid), but your scenario looks like subclassing is the way
to go; you have a UserForForum class, which is a more specialized form
of User.
A way of extending a class like a module doesn’t exist in Ruby afaik.
On Wed, Jan 9, 2013 at 11:33 PM, Calvin Bornhofen [email protected] wrote:
Hello,
I don’t know if my tip applies for you (haven’t worked with neither Rails
nor Mongoid), but your scenario looks like subclassing is the way to go; you
have a UserForForum class, which is a more specialized form of User.
I also believe that is what is called for here.
A way of extending a class like a module doesn’t exist in Ruby afaik.
Well, it does because you can extend anything:
irb(main):001:0> module M; def honk; puts “—”; end end
=> nil
irb(main):002:0> o = Object.new
=> #Object:0x8004cf9c
irb(main):003:0> o.extend M
=> #Object:0x8004cf9c
irb(main):004:0> o.honk
1.9.3p327 :001 > class M; def honk; puts “—”; end end
=> nil
1.9.3p327 :002 > o = Object.new
=> #Object:0x007fb679293268
1.9.3p327 :003 > o.extend M
TypeError: wrong argument type Class (expected Module)