Skip to content

Instantly share code, notes, and snippets.

@ggPeti

ggPeti/ext.rb

Created Sep 3, 2014
Embed
What would you like to do?
Arrow-like proc handling in Ruby
class Object
def itself
self
end
%i[> >> * &].each { |method| define_method(method) { |*args| to_proc.send method, *args } }
end
class Proc
def > other
-> *xs { other.to_proc.(*self.(*xs)) }
end
def >> other
-> *xs { other.to_proc.(self.(*xs)) }
end
def * other
-> *xs, x { [*self.(*xs), other.to_proc.(x)] }
end
def & other
-> *xs { [*self.(*xs), other.to_proc.(*xs)] }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.