[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: problem with Module#append_features

Michael Granger

9/12/2003 3:03:00 AM

On Monday, September 8, 2003, at 01:54 PM, Dan Doel wrote:

> Here's some black magic to do something like you want to do. If
> there's an easier way, I'm sure
> someone will post it as a follow-up to my message. :)
>
> [...]

How about:

module Bar
def initialize( *args )
puts "Initializing the M of #{self.inspect}"
end
end

class Foo
include Bar
def initialize( *args )
puts "Initializing #{self.inspect}"
super
end
end

f = Foo::new

# Output:
# verrin pts/ttyp1 [~]
# 3/502 {0}$ ruby -v ~/source/experiments/inimod.rb
# ruby 1.8.0 (2003-08-22) [powerpc-darwin]
# Initializing #<Foo:0xa9904>
# Initializing the M of #<Foo:0xa9904>



--
Michael Granger <ged@FaerieMUD.org>
Rubymage, Believer, Architect
The FaerieMUD Consortium <http://www.FaerieMU...