From: Robert Klemme Date: 2006-05-06T05:33:23+09:00 Subject: Re: Extending Core Classes - Best Practices 2006/5/5, Pistos Christou : > 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? '>'"? 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/