Harry Ohlsen <harryo / zip.com.au> wrote: > Dave Thomas wrote: > > > Steve Tuckner <SAT / MULTITECH.com> writes: > > > >> Is there a built in way to handle conversion of hex values in strings to > >> integers? Examples of possible syntax if it doesn't exist > >> > >> "0xF0".to_i # have it handle leading 0x for hex or 0 for octal > > > > "0xF0".hex > > > > > > It's a method in String > > It's an interesting point, though, in that you have to know, in advance, > that the string is a hex value (which you would most of the time, but I > could imagine cases where you have user interaction and it would be nice to > allow them to use '0' or '0x' prefixes if they want to). > > Obviously, the programmer can do a quick test, but since this is fairly > entrenched idiom, perhaps String#to_i could include the test? > > IMHO that would be the "least surprising" to the average programmer :-). > > Alternatively, it sounds like a sufficiently useful thing to add as a new > method of String. Try Integer() :) I don't use String#to_i much since Integer() actually checks syntax a bit. -- Brian Fundakowski Feldman \ FreeBSD: The Power to Serve! / green / FreeBSD.org `------------------------------'