# # # # # # # # #
# /29/regexp2proc.rb
#
# by Jan Lelis
# e-mail: mail@janlelis.de
# type/version: ruby
# snippet url: http://rbJL.net/29/regexp2proc.rb
# original post: http://rbJL.net/29-become-a-proc-star
# license: CC-BY (DE)
#
# (c) 2010 Jan Lelis.
# Use this with string arrays
class Regexp
def to_proc
Proc.new{ |e|
e.to_s[self]
}
end
end
# usage
# %w|just another string array|.map &/[jy]/ # => ["j", nil, nil, "y"]
# %w|just another string array|.select &/[jy]/ # => ["just", "array"]