From: "David A. Black" Date: 2008-07-03T01:34:26+09:00 Subject: Re: Ranges and Enumerable problems 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!