Skip to content

Instantly share code, notes, and snippets.

@azolotko
Created April 28, 2015 09:41
Show Gist options
  • Save azolotko/2bbd29a5ff4501c41a7a to your computer and use it in GitHub Desktop.
Save azolotko/2bbd29a5ff4501c41a7a to your computer and use it in GitHub Desktop.
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