From: Joel VanderWerf Date: 2009-07-21T03:20:51+09:00 Subject: getting char from string as fixnum in 1.8 and 1.9 What's the best way to write this program so that it will run correctly on both 1.8 and 1.9? This works, but I'm just curious if there's anything better, preferably without the RUBY_VERSION test, without adding methods to String, and without losing much efficiency compared with 1.8's String#[]. if RUBY_VERSION =~ /\A1\.9/ def third_char_as_fixnum(s) s[2].ord end else def third_char_as_fixnum(s) s[2] end end s = "abc" p third_char_as_fixnum(s) # ==> 99 -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407