From: "Ara.T.Howard" Date: 2005-09-15T14:01:34+09:00 Subject: Re: defining a method relative to a module's nesting On Thu, 15 Sep 2005, Trans wrote: > > module X > def self.included(mod) > define_method ... # define method from here > end > end > > module N > # <- define method to this namespace (N) > module M > include X > end > end > > T. one way: harp:~ > cat a.rb module X def self::included other class << other eval <<-code def foo 42 end code end super end end module N module M include X end end p N::M::foo harp:~ > ruby a.rb 42 nicer way: harp:~ > cat a.rb module X module ClassMethods def foo 42 end end module InstanceMethods def foo 'forty-two' end end def self::included other other.module_eval{ extend ClassMethods include InstanceMethods } end end class N class M include X end end p N::M::foo nm = N::M::new p nm.foo harp:~ > ruby a.rb 42 "forty-two" kind regards. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | Your life dwells amoung the causes of death | Like a lamp standing in a strong breeze. --Nagarjuna ===============================================================================