Skip to content

Instantly share code, notes, and snippets.

@vderyagin
Created January 26, 2012 11:00
Show Gist options
  • Save vderyagin/1682244 to your computer and use it in GitHub Desktop.
Save vderyagin/1682244 to your computer and use it in GitHub Desktop.
trick with Regexp and to_proc
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