Skip to content

Instantly share code, notes, and snippets.

@deanh
Created September 13, 2014 02:04
Show Gist options
  • Save deanh/51062c67e006783f694a to your computer and use it in GitHub Desktop.
Save deanh/51062c67e006783f694a to your computer and use it in GitHub Desktop.
class List
attr_reader :head, :tail
def self.from_ar ar
if h = ar.shift
self.new h, self.from_ar(ar)
end
end
def initialize head, tail = nil
@head = head
@tail = tail
end
def each &block
block.call head
if tail
tail.each &block
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment