a new delegation technique :-)

D

David A. Black

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

:)


David
 
J

James G. Britt

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
 
P

Phil Tomson

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
 
R

Robert Klemme

David A. Black said:
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:
=> 2

:))

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top