Skip to content

Instantly share code, notes, and snippets.

@dcki
Created May 31, 2014 23:44
Show Gist options
  • Save dcki/ddbe82d871465838728d to your computer and use it in GitHub Desktop.
Save dcki/ddbe82d871465838728d to your computer and use it in GitHub Desktop.
class Node
attr_accessor :children
def initialize
@children = []
end
def to_s
"Node with children #{children.to_s}"
end
end
a = Node.new
a.children << Node.new
a.children[0].children << a
puts a
# Output: Node with children [Node with children [Node with children [...]]]
# (Literal ellipsis were included in output, I didn't add them.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment