From: Siep Korteling Date: 2008-12-08T21:30:15+09:00 Subject: Re: A quetion about ruby string Zhao Yi wrote: (...) > > 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. pattern.instance_of? String But why check if it is a string or a regexp, when Regexp.new accepts both? def match(pattern) puts "Hello" =~ Regexp.new(pattern) end r = /ello/ puts r.instance_of?(Regexp) match(r) s = "ello" match(s) hth, Siep -- Posted via http://www.ruby-forum.com/.