Re: Why, oh, why, little regexp?
- From: 7stud -- <bbxx789_05ss@xxxxxxxxx>
- Date: Wed, 31 Oct 2007 21:46:56 +0900
Gavin Kistner wrote:
On Oct 30, 9:30 pm, Daniel Waite <rabbitb...@xxxxxxxxx> 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/.
.
- Follow-Ups:
- Re: Why, oh, why, little regexp?
- From: James Edward Gray II
- Re: Why, oh, why, little regexp?
- References:
- Why, oh, why, little regexp?
- From: Daniel Waite
- Re: Why, oh, why, little regexp?
- From: Daniel Waite
- Re: Why, oh, why, little regexp?
- From: Phrogz
- Why, oh, why, little regexp?
- Prev by Date: Re: Rubyconf Attendees
- Next by Date: Can we define data types explicitly?
- Previous by thread: Re: Why, oh, why, little regexp?
- Next by thread: Re: Why, oh, why, little regexp?
- Index(es):
Relevant Pages
|