From: zdennis Date: 2006-04-11T22:26:56+09:00 Subject: Re: Adding both class and instance/object methods from a Module? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Daniel Berger wrote: > > I'm coming into this thread late, but I think I'm missing something > here. What's wrong with this? > > module Foo > attr_accessor :meth_a > end > > class Bar > include Foo > extend Foo > end > > p Bar.meth_a # nil > Bar.meth_a = 'test' > p Bar.meth_a # 'test' > > bar = Bar.new > p bar.meth_a # nil > bar.meth_a = 'test' > p bar.meth_a # 'test' > I was thinking that Sam wasn't looking for the same interface at both the instance and class levels. I was thinking he wanted the equivalent of if including Modules also brought in the module levels methods. module M def self.foo "foo" end def bar "bar" end end class A include M end A.foo # => "foo" A.new.bar => "bar" Given the above code is what I think Sam was hoping to achieve, that's why I focused on giving the example of getting that functionality using include/extend. Zach -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFEO6+2Myx0fW1d8G0RAkFCAJ9O18EbMh+Gw0JlkPlpKzRlgg+wggCfR6pw M6eDIGIPd4kxiGC9FlgT2fQ= =vo3z -----END PGP SIGNATURE-----