Created
April 28, 2015 09:41
-
-
Save azolotko/2bbd29a5ff4501c41a7a to your computer and use it in GitHub Desktop.
This file contains 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
require 'ostruct' | |
o = OpenStruct.new(value: 1, tail: OpenStruct.new(value: 2, tail: OpenStruct.new(value: 3, tail: nil))) | |
def reverse(list, rest = nil) | |
result = cons(list.value, rest) | |
if list.tail.nil? | |
result | |
else | |
reverse(list.tail, result) | |
end | |
end | |
def cons(value, rest) | |
OpenStruct.new(value: value, tail: rest) | |
end | |
puts reverse(o) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment