Skip to content

Instantly share code, notes, and snippets.

@davidmyersdev
Created November 10, 2017 15:46
Show Gist options
  • Select an option

  • Save davidmyersdev/4c701c28e3fbd0b004360b04e3e7555f to your computer and use it in GitHub Desktop.

Select an option

Save davidmyersdev/4c701c28e3fbd0b004360b04e3e7555f to your computer and use it in GitHub Desktop.
A helper method for passing params while expanding Procs.
def s(method, *params)
return Proc.new do |o|
r = o.send(method, *params)
next yield(r) if block_given?
r
end
end
# without helper
[['hello', nil], ['world', 2]].map { |x| x[0].capitalize }.compact # => ["Hello", "World"]
# with helper
[['hello', nil], ['world', 2]].map(&s(:[], 0, &:capitalize)).compact # => ["Hello", "World"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment