From: Robert Klemme Date: 2010-01-20T18:54:12+09:00 Subject: Re: Looking for object.inherits?(Classname) 2010/1/20 Shot (Piotr Szotkowski) : > Robert Klemme: > >> irb(main):010:0> a = [] >> => [] > > […] > >> irb(main):015:0> Enumerable === a >> => true > >> Note that I do not recommend using the test from line 12 as it is >> likely much more inefficient than the other ones.  The test from line >> 15 is especially suited for use with "case" statements as in > >> case a >> when Enumerable >>   puts "it's enumerable" >> when Array, Hash >>   puts "It's a special enumerable" >> when Integer >>   puts "You can count on me." >> else >>   puts "No idea about a." >> end > > A minor nitpick: Note that due to case’s behaviour (once a ‘when’ > matches, other ‘whens’ are ignored), the above will almost never¹ > print ‘It's a special enumerable’, as Arrays and Hashes are almost > always¹ Enumerable. Testing for Array/Hash first and Enumerable > second would make more sense in most cases. Oh, yes of course! Thanks for catching that! The order should have been reversed. case a when Array, Hash puts "It's a special enumerable" when Enumerable puts "it's enumerable" when Integer puts "You can count on me." else puts "No idea about a." end Thanks again! Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/