Skip to content

Instantly share code, notes, and snippets.

@headius
Created September 17, 2010 15:34
Show Gist options
  • Save headius/584401 to your computer and use it in GitHub Desktop.
Save headius/584401 to your computer and use it in GitHub Desktop.
class Proc
def <<(other)
case other
when Proc
Proc.new do |*args|
call(other.call(*args))
end
else
call(other)
end
end
def >>(other)
raise TypeError unless Proc === other
Proc.new do |*args|
other.call(call(*args))
end
end
end
times6 = ->(i){ i * 2 } << ->(i){ i * 3 }
times2plus1 = ->(i){ i * 2} >> ->(i){ i + 1 }
puts times6.call(3)
puts times2plus1.call(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment