[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

a new delegation technique :-

dblack

2/24/2005 2:37:00 PM

3 Answers

ruby talk

2/24/2005 2:51:00 PM

0

On Thu, 24 Feb 2005 23:37:26 +0900, David A. Black <dblack@wobblini.net> wrote:
> Hi --
>
> This probably lies somewhere between obfuscated and pointless, but I
> thought it was a fun example of Ruby's nimbleness:
>
> class C
> attr_reader :to_s
> def initialize(str)
> @to_s = str
> end
> end
>
> s = C.new("hello")
> puts s # hello
>
> :-)

Ah.

I would put it in the pointfuscated group.

James


ptkwt

2/24/2005 2:53:00 PM

0

In article <Pine.LNX.4.61.0502240635380.25193@wobblini>,
David A. Black <dblack@wobblini.net> wrote:
>Hi --
>
>This probably lies somewhere between obfuscated and pointless, but I
>thought it was a fun example of Ruby's nimbleness:
>
>
> class C
> attr_reader :to_s
> def initialize(str)
> @to_s = str
> end
> end
>
> s = C.new("hello")
> puts s # hello
>
>:-)

Cool.

I read the subject of your post and thought that perhaps you were going to
ask if someone else would organize RubyConf this year ;-)

Phil

Robert Klemme

2/24/2005 2:54:00 PM

0


"David A. Black" <dblack@wobblini.net> schrieb im Newsbeitrag
news:Pine.LNX.4.61.0502240635380.25193@wobblini...
> Hi --
>
> This probably lies somewhere between obfuscated and pointless,

LOL - I have to make a note for this localization. :-)

> but I
> thought it was a fun example of Ruby's nimbleness:
>
>
> class C
> attr_reader :to_s
> def initialize(str)
> @to_s = str
> end
> end
>
> s = C.new("hello")
> puts s # hello
>
> :-)

With the added

class C
alias :to_str :to_s
end

You can even do this:

>> /ll/ =~ s
=> 2

:-))

robert