From: "David A. Black" Date: 2010-05-17T21:29:46+09:00 Subject: Re: Range on strings. Hi -- On Fri, 14 May 2010, Vikrant Chaudhary wrote: > Hi, > If I do - > > ('A'..'Z').include?('AA') > > It returns "true", while > > ('A'..'Z').to_a.include?('AA') > > (of course) returns "false". Is it intentional or possibly a bug? > I'm using ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux] on > Ubuntu 10.04 x64 As per the other answers, it's because ('A'..'Z').to_a is an array of discrete values, whereas ('A'..'Z') is a range with a start and end. I'll just add that in Ruby 1.9, things have changed so that include? on a range is, I think, the same as .to_a.include? and the behavior of the old include? is found in Range#cover? $ ruby191 -e 'p(("A".."Z").include?("AA"))' false $ ruby191 -e 'p(("A".."Z").cover?("AA"))' true include? is also available under the name member?, which I think is a little clearer (both because include? used to mean something else, and because being a "member" of a range doesn't really make sense so it almost has to mean something other than just being within the range). David -- David A. Black, Senior Developer, Cyrus Innovation Inc. THE Ruby training with Black/Brown/McAnally COMPLEAT Coming to Chicago area, June 18-19, 2010! RUBYIST http://www.compleatrubyist.com