Created
September 13, 2014 02:04
-
-
Save deanh/51062c67e006783f694a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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