Raise unless RUBY_VERSION[%r/^\s*\d+\.\d+/o].to_f >= 1.8

On Tue, 25 Nov 2003, Gennady wrote:

> It does not work as a general solution, as “1.11.0” < “1.8.0”. However,

    [...]

ah yes - did think of that at one point. must have drank more coffee that

    [...]

at one point, i created a Version class which used the rules that ‘ld’

follows:

interface.age.revision

etc. etc.

See my previous post about the Version class from RubyGems. It handles
the cases that you need.

if

http://www.eng.cse.dmu.ac.uk/~hgs/ruby/revision.rb

is any use…

Chad

    Hugh
···

On Tue, 25 Nov 2003, Chad Fowler wrote:

On Tue, 25 Nov 2003, Ara.T.Howard wrote:

“T. Onoma” transami@runbox.com schrieb im Newsbeitrag
news:200311250144.03230.transami@runbox.com

“T. Onoma” transami@runbox.com schrieb im Newsbeitrag
news:200311250002.09555.transami@runbox.com

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’ :slight_smile:

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
···

On Tuesday 25 November 2003 10:07 am, Robert Klemme wrote:

On Tuesday 25 November 2003 08:07 am, daz wrote:

Nice!

Could string be added too? So that:

t = Tuple(‘1.8.1’)
rv = Tuple(RUBY_VERSION)

That would be really sweet. I’ll have to add this to my stash of libraries. :slight_smile:

-t0

···

On Tuesday 25 November 2003 11:22 am, Robert Klemme wrote:

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

Hi –

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

Or perhaps:

module Kernel
def Tuple(*a)
t = *a
t.extend(Comparable)
end
end

(Disclaimer: I’m not a real tuple theorist, so I’m winging it a bit
here.)

David

···

On Tue, 25 Nov 2003, Robert Klemme wrote:


David A. Black
dblack@wobblini.net

“T. Onoma” transami@runbox.com schrieb im Newsbeitrag
news:200311250344.18704.transami@runbox.com

···

On Tuesday 25 November 2003 11:22 am, Robert Klemme wrote:

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

Nice!

Could string be added too? So that:

t = Tuple(‘1.8.1’)
rv = Tuple(RUBY_VERSION)

That would be really sweet. I’ll have to add this to my stash of
libraries. :slight_smile:

Exercise left for the reader. :slight_smile:

robert