Robert Klemme wrote:
> def add_token(tok_id, re)
>    @rules << Rule.new(tok_id,
>      case re
>      when String
>        Regexp.new(re)
>      when Regexp
>        re
>      else
>        raise ArgumentError, "Neither String nor regexp"
>      end)
> end

or even just this:

def add_token(tok_id, re)
  @rules << Rule.new(tok_id, Regexp.new(re))
end

That's not exactly the same since Regexp.new(a_regexp) does actually 
create a new regexp object, but AFAICT it's a functionally identical 
regexp.

>> r1 = /foo/i
=> /foo/i
>> r2 = Regexp.new(r1)
=> /foo/i
>> r1 == r2
=> true
>> r1.equal?(r2)
=> false
-- 
Posted via http://www.ruby-forum.com/.