jeffz_2002
12/20/2006 10:22:00 PM
You'll probably have 10 (better) answers for this by the time I've
posted, but here's mine:
a = "something is here"
b = [ 'x', 'y', 'g', 'q', 'z' ]
b.find { |c| Regexp.new( c ).match( a ) } => "g"
The regexp.new creates a new regex (surprise) like /c/, and then
searches for it in the string a. If it's not found, match returns nil,
which is false, so find continues. If it's found, match is an object,
which is true, so find exits with that item from the array.
> this is what I've been trying to do.
> array.find {|b| b == @string}.to_s
> this does't work I know, but I'm I in the right direction?
The find is on the right track, but what you're saying is that the
array item must match the full string ... which, based on your problem
description, is incorrect.
jz