From: Zhao Yi Date: 2008-12-08T21:01:20+09:00 Subject: Re: A quetion about ruby string F. Senault wrote: > And, on top of what the others have said, you don't need the forward > slashes - they're Ruby (and Perl, and...) constructs, not part of the > regexp. Otherwise : > >>> a = "/abc[def]/" > => "/abc[def]/" >>> Regexp.new(a) > => /\/abc[def]\// >>> b = "abc[def]" > => "abc[def]" >>> Regexp.new(b) > => /abc[def]/ > > (Be careful if you have Wirble installed ; mine completely suppresses > all the /, which kinda defeats the purpose of the exercise...) > > Fred Does Ruby support RTTI (runtime type identification)? This problem is that the type of the parameter should be Regexp instance, however ruby doesn't check type on the method declaration. So I am looking for this kind of method: def match(pattern) if pattern instanceof String p = Regexp.new(pattern) end ... end In this way, I can check the type of the parameter so that the client code doesn't need to change. -- Posted via http://www.ruby-forum.com/.