K
kimersen
Hi,
I'm playing around with ruby trying to understand whats going on, and
here is something I don't understand.
class ZNum
def initialize(n)
@n=n
end
def to_s
self.class
end
end
n = ZNum.new(1234)
puts n # prints #<ZNum:0xb75dfcc8>
puts n.to_s # prints ZNum
In both cases it uses ZNum#to_s, but the results are different. Why?
/kim
I'm playing around with ruby trying to understand whats going on, and
here is something I don't understand.
class ZNum
def initialize(n)
@n=n
end
def to_s
self.class
end
end
n = ZNum.new(1234)
puts n # prints #<ZNum:0xb75dfcc8>
puts n.to_s # prints ZNum
In both cases it uses ZNum#to_s, but the results are different. Why?
/kim