Created
January 26, 2012 11:00
-
-
Save vderyagin/1682244 to your computer and use it in GitHub Desktop.
trick with Regexp and to_proc
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
| class Regexp | |
| def to_proc | |
| Proc.new { |arg| arg =~ self } | |
| end | |
| end | |
| # select behaves like as Enumerable#grep: | |
| %w(foo bar baz boo fooz goo).select &/oo/ # => ["foo", "boo", "fooz", "goo"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment