Skip to content

Instantly share code, notes, and snippets.

@netoneko
Last active December 26, 2015 15:39
Show Gist options
  • Select an option

  • Save netoneko/7174768 to your computer and use it in GitHub Desktop.

Select an option

Save netoneko/7174768 to your computer and use it in GitHub Desktop.
require 'binding_of_caller'
class Symbol
def ~
this = binding.of_caller(1).eval("self")
this.method(self).to_proc
end
end
def x
"hello!"
end
def sum(a, b)
a + b
end
def call(z)
z.call
end
puts call ~:x
def three_plus_two(sum_function)
sum_function.call(3, 2)
end
puts three_plus_two ~:sum
puts (~:sum)[7, 13]
one_two_three = [1, 2, 3]
puts one_two_three.reduce(0, &~:sum)
puts one_two_three.reduce(0, &:+)
def y
def hello(name)
"Hello, #{name}!"
end
~:hello
end
puts one_two_three.map(&y).inspect
plus_three = (~:sum).curry[3]
puts one_two_three.map(&plus_three).inspect
puts one_two_three.map(&plus_three).reduce(0, &~:sum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment