Skip to content

Instantly share code, notes, and snippets.

@padde

padde/array_to_proc.rb

Last active Aug 29, 2015
Embed
What would you like to do?
Pass arguments to Ruby shortcut procs
class Array
def to_proc
->(obj) { obj.public_send *self }
end
end
input = <<EOS
foo,bar,baz
hello,world
1,2,3
EOS
input.lines
.map(&:chomp)
.map(&[:split, ','])
.map(&[:join, '+'])
.join('--')
# => "foo+bar+baz--hello+world--1+2+3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment