-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Am 01.10.2006 um 21:14 schrieb David Vallner:

> Florian A?mann wrote:
>> To be complete here if the Exception:
>>
>> NameError: undefined local variable or method `role' for
>> #<Class:#<Person:0x2869aa0>>
>>
>
> I smell a Ruby bug / gotcha.
>
> Apparently, in metaclass scope, the surrounding scope just isn't  
> visible.
>
> Try a workaround:
>
> person.roles.each do |role|
>     if role.class.const_defined?('Functions')
>         class << person
> 	    self
>         end.class_eval do
>             include role.class.const_get('Functions')
>         end
>     end
> end unless person.nil?
>
> David Vallner
>
> PS: Statement modifiers after whole blocks? Ick.
>

Ok, I just tested it, but now even a person with a CustomerRole and  
no ManagerRole role has the methods once they are included, thanks  
anyway. :D
dblack, extend works excactly the way I want it to, thank you too :)

Result...

if person = self.send( dyn_finder, *find_args )
     m_name = 'Functions'
     functions = person.roles.inject([]) do |f,r|
         r.class.const_defined?(m_name) and
         f << r.class.const_get(m_name)
     end and person.extend *functions
end

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iD8DBQFFICUhl1R1ZNDW4WgRAtJUAJ9mHsq/PLfad6hdR8xxFm+Ep6xDKgCggz4D
5NuWkFwTIcalG5cAOnxbP4M=
=1k6o
-----END PGP SIGNATURE-----