From: Glen Holcomb Date: 2008-07-03T01:56:31+09:00 Subject: Re: Ranges and Enumerable problems ------=_Part_2254_5416531.1215017971421 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Wed, Jul 2, 2008 at 10:34 AM, David A. Black wrote: > Hi -- > > > On Thu, 3 Jul 2008, Glen Holcomb wrote: > > On Wed, Jul 2, 2008 at 9:12 AM, Robert Klemme > > >> wrote: >> >> 2008/7/2 Glen Holcomb : >>> >>>> Okay so when I play with "!".."~" wrong things happen. >>>> >>>> ("!".."~").include?("W") >>>> true >>>> >>>> ("!.."~").include?(" ") >>>> false >>>> >>>> so far so good, however. >>>> >>>> ("!".."~").each do |c| >>>> puts c >>>> end >>>> >>>> ! >>>> " >>>> # >>>> $ >>>> % >>>> & >>>> ' >>>> ( >>>> ) >>>> * >>>> + >>>> , >>>> - >>>> . >>>> / >>>> 0 >>>> 1 >>>> 2 >>>> 3 >>>> 4 >>>> 5 >>>> 6 >>>> 7 >>>> 8 >>>> 9 >>>> => "!".."~" >>>> >>>> This is wrong! >>>> >>>> ("!".."~").last >>>> => "~" >>>> >>>> This is also right. >>>> >>>> It looks to me like a problem with the Enumerable mixin but I guess the >>>> question is why? >>>> >>> >>> Note this >>> >>> irb(main):003:0> "9".succ >>> => "10" >>> >>> Try this instead: >>> >>> (?!..?~).each {|c| p c.chr} >>> >>> irb(main):008:0> (?!..?~).include? ?\ >>> => false >>> >>> Thanks Robert, >> >> That is interesting. I wonder why it doesn't work as you would expect. >> The >> range object seems to be correct (at least through limited include? >> testing) >> however it returns incomplete info whenever you use an Enumerable method >> or >> a method that appears to use an Enumerable method. >> > > In 1.9 you get this: > > ('!'..'~').to_a >>> >> => ["!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", > ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", > "<", "=", ">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", > "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", > "X", "Y", "Z", "[", "\\", "]", "^", "_", "`", "a", "b", "c", "d", "e", > "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", > "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~"] > > > David > > -- > Rails training from David A. Black and Ruby Power and Light: > Intro to Ruby on Rails July 21-24 Edison, NJ > Advancing With Rails August 18-21 Edison, NJ > See http://www.rubypal.com for details and updates! > > Thanks David, That is good to know. Maybe I should upgrade. -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I can't hear a word you're saying." -Greg Graffin (Bad Religion) ------=_Part_2254_5416531.1215017971421--