From: Joel VanderWerf Date: 2009-07-21T05:39:20+09:00 Subject: Re: getting char from string as fixnum in 1.8 and 1.9 brabuhr@gmail.com wrote: >> ruby -v -e 'p "foo"[2].ord' > ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-linux] > -e:1: undefined method `ord' for 111:Fixnum (NoMethodError) > >> cat foo.rb > unless 0.respond_to?(:ord) > class Integer > def ord; self; end > end > end > >> ruby -v -rfoo -e 'p "foo"[2].ord' > ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-linux] > 111 > > Still meets the constraint: "without adding methods to String" > :-) That seems like a pretty good approach, actually, and it happens to be what the snmp gem does (lib/ber.rb): # # Add ord method to Fixnum for forward compatibility with Ruby 1.9 # if "a"[0].kind_of? Fixnum unless Fixnum.methods.include? :ord class Fixnum def ord; self; end end end end -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407