Skip to content

Instantly share code, notes, and snippets.

@asterite
Created April 4, 2015 23:19
Show Gist options
  • Save asterite/b9128bbba95e2419bc85 to your computer and use it in GitHub Desktop.
Save asterite/b9128bbba95e2419bc85 to your computer and use it in GitHub Desktop.
class Node
include Enumerable(self)
property left, right, data
def initialize(@data)
end
def each(&block : Node ->)
left.try &.each(&block)
block.call(self)
right.try &.each(&block)
end
end
one = Node.new 1
two = Node.new 2
two.left = one
# Works
two.each do |node|
p node
end
# Doesn't work :-(
# two.each_with_index do |node, i|
# p 1
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment