Hi,

I'm trying to create a Regexp object by calling eval like this:

def eval_to_regexp(o)
  if o.is_a?(Regexp)
    o
  elsif o.is_a?(String)
    o = o[5..o.size] if o[0..4] == 'eval:'
    eval("/#{o}/")
  else
    eval("/#{o.to_s}/")
  end
end

e = eval_to_regexp("eval:some_function() + '^'")

Suppose some_function() returns the string '/home/test'

And then I use it to test a match as follows:

'/home/test' =~ e # should return 0
'/home/test/somethingelse' =~ e # should return nil (because of the '^'
above)

I also tried using /#{o}/ directly instead of the eval, but it doesn't
work either :(

Thanks in advance!

- Ivan V.

-- 
Posted via http://www.ruby-forum.com/.