On May 5, 2006, at 4:33 PM, Robert Klemme wrote:

> 2006/5/5, Pistos Christou <jesusrubsyou.5.pistos / geoshell.com>:
>> Hi, all.
>>
>> I've been following the "Sharp knives and glue" thread.  It's  
>> gotten me
>> thinking about the things I've already been doing with Ruby.  I  
>> wanted
>> to ask for opinions on when it is good, bad, acceptable to extend  
>> core
>> classes like String, Fixnum, Array, Hash.
>>
>> To be a bit more concrete: Would it be okay to tack on "is?" and  
>> "has?"
>> type methods?  Contrived example:
>>
>> class String
>>     VOGON_VOCABULARY = [
>>         'freddled', 'gruntbuggly', 'micturations', 'plurdled',
>>         'gabbleblotchits', 'lurgid', 'groop', 'foonting',
>>         'turlingdromes', 'hooptiously', 'drangle', 'bindlewurdles',
>>         'gobberwarts', 'blurglecruncheon',
>>     ]
>>
>>     VOGON_REGEXP = /#{VOGON_VOCABULARY.join('|')}/i
>>
>>     def vogon?
>>         ( VOGON_REGEXP =~ self ).respond_to? '>'
>>     end
>> end
>
> What exactly do you intend to achieve with ".respond_to? '>'"?
>

I think he's trying to make sure the result is a number and therefore  
the regexp matched, rather than nil or false. Of course I don't see  
why he didn't just do

def vogon?
   VOGON_REGEXP =~ self
end

Or if he want to make sure vogon? would return either true or false:

def vogon?
   !!(VOGON_REGEXP =~ self)
end

or as you mentioned ===


> And, btw, this sounds very specialized - it's certainly ok as part of
> a script. I wouldn't put it into a lib though.
>
> A simpler solution might be to just do
>
> VOGON === "bluh"
>
> where VOGON is your RX.
>
> Kind regards
>
> robert
>
>
> --
> Have a look: http://www.flickr.com/photos/fussel-foto/
>