From: Robert Klemme Date: 2003-11-25T19:22:21+09:00 Subject: Re: raise unless RUBY_VERSION[%r/^\s*\d+\.\d+/o].to_f >= 1.8 "T. Onoma" schrieb im Newsbeitrag news:200311250144.03230.transami@runbox.com... > On Tuesday 25 November 2003 10:07 am, Robert Klemme wrote: > > "T. Onoma" schrieb im Newsbeitrag > > news:200311250002.09555.transami@runbox.com... > > > > > On Tuesday 25 November 2003 08:07 am, daz wrote: > > > > RUBY_VERSION = "1.8.1" > > > > p RUBY_VERSION >= "1.8" #-> true > > > > RUBY_VERSION = "1.10.1" > > > > p RUBY_VERSION >= "1.8" #-> false > > > > > > > > .... but MINOR 10 would upset RUBY_VERSION_CODE (in version.h) > > > > which, incidentally, would be a useful global (eventually). > > > > > > > > It might take the pressure off Matz if 1.9 didn't have to be > > > > followed by 2.0 tho' :-) > > > > > > > > > unless someone can think of a reason not to - i'll take it! > > > > > > > > Um, because it's crufty (looks like we can't tell the difference > > > > between Numeric and String sorting sequence - even though I've > > > > seen it used a lot in Ruby). > > > > > > Any one think Ruby needs a Tuple class? > > > > It's already there: Array. > > No, > > class Tuple < Array > include Comparable > end > > class Array > def to_t > return Tuple.new(self) > end > end Better define this in Enumerable: module Enumerable def to_t return Tuple.new(self) end end > Now is has a Tuple. Try, > > ruby_version = RUBY_VERSION.split('.').collect { |i| i.to_i }.to_t > > puts ruby_version > puts ruby_version >= [1,7,1] > puts ruby_version >= [1,8] > puts ruby_version >= [1,8,1] > puts ruby_version >= [1,10] > > Although a Tuple a.b.c ... literal would look better. Nothing easier than that. You can do module Kernel def Tuple(*a) a = a[0] if a.size == 1 and a[0].kind_of? Enumerable a = a.to_a unless a.kind_of? Array a.extend Comparable end end t1 = Tuple( [1,2,3] ) t2 = Tuple( 1, 3, 4 ) p t1 < t2 robert