I like where Ara is going and I like where Naseby went. I think both of
these solutions go hand in hand. Included is an example/test usage (yes it
runs) of how it appeals to me.
Basically they should both be 'traits'. Please see example rb file for more
information.
i actually had the whole thing wrapped in a Traits module... i'm ok with this
approach if people don't mind doing an include. one other positive thing is
that this does not pollute Module and Class with new methods...
i'll bang out a
module Trait
module AccessorTraits
end
end
now and read more about MethodTraits before tackling - this was a nice
diversion while i've been on leave but 'real' work starts back up today so i
won't have time for a while...
cheers.
--------------080906010603050401010206
Content-Type: text/plain;
name="traits.rb"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="traits.rb"
module Trait
##
# use append_features so if the user includes Trait it will get everything
# from with AccessorTrait and MethodTrait also. see
def self.append_features( aModule )
constants.each { |c| aModule.instance_eval( "include #{c}" ) }
end
module AccessorTraits
# include Ara's code here
def trait( arg )
puts "#{self} has trait #{arg}"
end
end
module MethodTraits
# include here the functionality from
# http://homepages.ihug.com.au/~naseby/33.html
def require_method( arg )
puts "#{self} has required method #{arg}"
end
end
end
## Example Usage
class A
# includes Trait, so it gets all of Traits functionality
include Trait
end
A.new.trait( :a )
A.new.require_method( :reqA )
puts
class B
# includes AccessorTraits, only gets AccessorTraits functionality
include Trait::AccessorTraits
end
begin
B.new.trait( :b )
B.new.require_method( :reqB )
rescue => ex
puts ex
end
puts
class C
# includes MethodTraits, only gets MethodTraits functionality
include Trait::MethodTraits
end
begin
C.new.trait( :b )
rescue => ex
puts ex
C.new.require_method( :reqC )
end
puts
--------------080906010603050401010206--
-a
···
On Wed, 4 May 2005, Zach Dennis wrote:
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
renunciation is not getting rid of the things of this world, but accepting
that they pass away. --aitken roshi
===============================================================================