-
-
Save davidmyersdev/4c701c28e3fbd0b004360b04e3e7555f to your computer and use it in GitHub Desktop.
A helper method for passing params while expanding Procs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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