Hi,
I'm just getting started with Ruby, and I've run into a head-scratcher. I have the following code:
I would've expected this output:Code ruby:class Node < Array def to_s puts(">>") tokens = self.each { |token| puts("$ " + token.to_s) token.to_s } puts("<<") "(" + tokens.join(" ") + ")" end end n = Node.new n.push(1) n.push(2) m = Node.new m.push(3) m.push(4) n.push(m) puts(n.to_s)
But instead, I get this:Code:>> $ 1 $ 2 >> $ 3 $ 4 << $ (3 4) << (1 2 (3 4))
Any ideas?Code:>> $ 1 $ 2 >> $ 3 $ 4 << $ (3 4) >> $ 3 $ 4 << << (1 2 3 4)




Bookmarks