Hi,

On Mon, Dec 08, 2008 at 09:01:20PM +0900, Zhao Yi wrote:
> 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.

imho, you can retype it to string by .to_s


cheers,

 V.


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