Skip to content

Instantly share code, notes, and snippets.

@markmeeus
Created December 20, 2013 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markmeeus/8052351 to your computer and use it in GitHub Desktop.
Save markmeeus/8052351 to your computer and use it in GitHub Desktop.
Ever wish there was a symol.to_proc style way to call methods with parameters?
class Array
class ArrayProcWrapper
attr_accessor :ary
def to_proc
lambda { |obj| obj.send self.ary.first, *self.ary[1..-1]}
end
end
def to_proc_wrapper
w = ArrayProcWrapper.new
w.ary = self
w
end
alias :tpw :to_proc_wrapper
end
#now you can do this
array = ["Marks awesome gist", "is really", "awesome"]
array.map(&[:split, ' '].tpw) #splits every string by spaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment