From: "trans. (T. Onoma)" Date: 2004-10-03T14:04:22+09:00 Subject: Re: Just Found Integer() On Sunday 03 October 2004 12:54 am, Ara.T.Howard@noaa.gov wrote: > been there for a while: > > harp:~ > /usr/bin/ruby -v -e'p Integer(42)' > ruby 1.6.8 (2002-12-24) [i386-linux-gnu] > 42 > > it's just a method that happens to also be a constant. > > harp:~ > /usr/bin/ruby -v -e'p Kernel.methods.grep(/Int/)' > ruby 1.6.8 (2002-12-24) [i386-linux-gnu] > ["Integer"] > > think of it like Kernel.open being shorthand for File::open - it makes > dirty scipts feel short and sweet - but it's really a class method of File. > the Integer and friend methods are better than, say String#to_i because > > harp:~ > /usr/bin/ruby -v -e'p "42abc".to_i' > ruby 1.6.8 (2002-12-24) [i386-linux-gnu] > 42 > > harp:~ > /usr/bin/ruby -v -e'p Integer("42abc")' > ruby 1.6.8 (2002-12-24) [i386-linux-gnu] > -e:1:in `Integer': invalid value for Integer: "42abc" (ArgumentError) > from -e:1 > > i use them all the time because of this - if fact, my post from earlier > today has the Integer() contruct in it ;-) But that sort of begs the question. Why not Integer['42abc'] ? T.