From: 7stud -- Date: 2007-10-31T21:46:56+09:00 Subject: Re: Why, oh, why, little regexp? Gavin Kistner wrote: > On Oct 30, 9:30 pm, Daniel Waite wrote: >> That's clever use of ?a, which I recognize but have never seen anyone >> use before. Thanks for the example! > > My current favorite use for the ?x syntax is converting single- > character strings representing digits into their integer form: > > # Jenny jenny, who can I turn to? > irb(main):006:0> "8675309".each_byte{ |x| p x - ?0 } > 8 > 6 > 7 > 5 > 3 > 0 > 9 Perhaps this is clearer: "8675309".each_byte{|code| puts code.chr} ...although slightly slower. -- Posted via http://www.ruby-forum.com/.