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

any better methods of require a specific version/set of versions?

-a

···

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

Ara.T.Howard wrote:

any better methods of require a specific version/set of versions?

-a

This might be a good thing to encapsulate somehow; perl has a construct
like so:

require 5;

which requires that the version of perl running the script be >= 5.
(IIRC, you can “require” arbitrary levels, like ``require 5.0.1;‘’, but
I might be mistaken on that.)

Given ruby is changing in fairly large chunks, this might be useful.

Moin!

Ara.T.Howard wrote:

any better methods of require a specific version/set of versions?

What about RUBY_VERSION >= “1.8.0”?

Regards,
Florian Gross

“Ara.T.Howard” ahoward@ngdc.noaa.gov schrieb im Newsbeitrag
news:Pine.LNX.4.44.0311241336440.28055-100000@fattire.ngdc.noaa.gov

any better methods of require a specific version/set of versions?

A bit more complicated, but could be included in the std. distribution…

module Kernel
def ensure_version( ver )
if ( RUBY_VERSION.split(/./).map{|x|x.to_i} <=>
ver.split(/./).map{|x|x.to_i} ) < 0
throw “Version error: should be #{ver} but is #{RUBY_VERSION}”
end
end
end

ensure_version “1.7.0”
ensure_version “1.8.0”
ensure_version “1.8.1”

Cheers

robert

require ‘rbconfig’

major = Config::CONFIG[‘MAJOR’].to_i
minor = Config::CONFIG[‘MINOR’].to_i
teeny = Config::CONFIG[‘TEENY’].to_i
if major < 1 or (major == 1 and minor < 8) then
raise “wrong version”
end

Of course, this can be wrapped into a nice version class. I wrote one
of these a long time ago and never released it, but there are plenty of
others already out there.

Paul

···

On Tue, Nov 25, 2003 at 08:32:14AM +0900, Ara.T.Howard wrote:

any better methods of require a specific version/set of versions?

Florian Gross wrote:

Moin!

Ara.T.Howard wrote:

any better methods of require a specific version/set of versions?

What about RUBY_VERSION >= “1.8.0”?

Or:

irb(main):001:0> RUBY_VERSION
=> “1.8.1”
irb(main):002:0> RUBY_VERSION.to_f
=> 1.8
irb(main):003:0> RUBY_VERSION.to_f >= 1.8
=> true

completely agreed.

-a

···

On Tue, 25 Nov 2003, Michael campbell wrote:

Date: Tue, 25 Nov 2003 08:41:34 +0900
From: Michael campbell michael_s_campbell@yahoo.com
Newsgroups: comp.lang.ruby
Subject: Re: raise unless RUBY_VERSION[%r/^\s*\d+.\d+/o].to_f >= 1.8

Ara.T.Howard wrote:

any better methods of require a specific version/set of versions?

-a

This might be a good thing to encapsulate somehow; perl has a construct
like so:

require 5;

which requires that the version of perl running the script be >= 5.
(IIRC, you can “require” arbitrary levels, like ``require 5.0.1;‘’, but
I might be mistaken on that.)

Given ruby is changing in fairly large chunks, this might be useful.

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

i thought about this for a while and came up with a good reason not to do this

  • but it currently eludes me!

unless someone can think of a reason not to - i’ll take it!

:wink:

-a

···

On Tue, 25 Nov 2003, Florian Gross wrote:

Date: Tue, 25 Nov 2003 08:54:02 +0900
From: Florian Gross flgr@ccan.de
Newsgroups: comp.lang.ruby
Subject: Re: raise unless RUBY_VERSION[%r/^\s*\d+.\d+/o].to_f >= 1.8

Moin!

Ara.T.Howard wrote:

any better methods of require a specific version/set of versions?

What about RUBY_VERSION >= “1.8.0”?

Regards,
Florian Gross

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

nice! you win paul!

-a

···

On Thu, 27 Nov 2003, Paul Brannan wrote:

Date: Thu, 27 Nov 2003 06:40:52 +0900
From: Paul Brannan pbrannan@atdesk.com
Newsgroups: comp.lang.ruby
Subject: Re: raise unless RUBY_VERSION[%r/^\s*\d+.\d+/o].to_f >= 1.8

On Tue, Nov 25, 2003 at 08:32:14AM +0900, Ara.T.Howard wrote:

any better methods of require a specific version/set of versions?

require ‘rbconfig’

major = Config::CONFIG[‘MAJOR’].to_i
minor = Config::CONFIG[‘MINOR’].to_i
teeny = Config::CONFIG[‘TEENY’].to_i
if major < 1 or (major == 1 and minor < 8) then
raise “wrong version”
end

Of course, this can be wrapped into a nice version class. I wrote one
of these a long time ago and never released it, but there are plenty of
others already out there.

Paul

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

Date: Tue, 25 Nov 2003 08:54:02 +0900
From: Florian Gross flgr@ccan.de
Newsgroups: comp.lang.ruby
Subject: Re: raise unless RUBY_VERSION[%r/^\s*\d+.\d+/o].to_f >= 1.8

Moin!

Ara.T.Howard wrote:

any better methods of require a specific version/set of versions?

What about RUBY_VERSION >= “1.8.0”?

Regards,
Florian Gross

i thought about this for a while and came up with a good reason not to
do this

  • but it currently eludes me!

unless someone can think of a reason not to - i’ll take it!

It does not work as a general solution, as “1.11.0” < “1.8.0”. However,
bearing in mind that Ruby so far had only 1-digit version components
and 1.9.x is going to be the last Ruby1 version (according to Matz),
this check may be OK.

Gennady

···

On Nov 24, 2003, at 20:42, Ara.T.Howard wrote:

On Tue, 25 Nov 2003, Florian Gross wrote:

:wink:

-a

ATTN: please update your address books with address below!

=======================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print
"\x3a\x2d\x29\x0a"”;done’
=======================================================================
========

Ara.T.Howard wrote:

any better methods of require a specific version/set of versions?

What about RUBY_VERSION >= “1.8.0”?

i thought about this for a while and came up with a good reason not to do this

  • but it currently eludes me!

Maybe this bothered you ?

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).

daz

···

“Ara.T.Howard” ahoward@ngdc.noaa.gov wrote:

On Tue, 25 Nov 2003, Florian Gross wrote:

not knocking paul’s solution or anything, but you prefer this to using a
tuple?

···

On Thursday 27 November 2003 12:12 am, Ara.T.Howard wrote:

On Thu, 27 Nov 2003, Paul Brannan wrote:

Date: Thu, 27 Nov 2003 06:40:52 +0900
From: Paul Brannan pbrannan@atdesk.com
Newsgroups: comp.lang.ruby
Subject: Re: raise unless RUBY_VERSION[%r/^\s*\d+.\d+/o].to_f >= 1.8

On Tue, Nov 25, 2003 at 08:32:14AM +0900, Ara.T.Howard wrote:

any better methods of require a specific version/set of versions?

require ‘rbconfig’

major = Config::CONFIG[‘MAJOR’].to_i
minor = Config::CONFIG[‘MINOR’].to_i
teeny = Config::CONFIG[‘TEENY’].to_i
if major < 1 or (major == 1 and minor < 8) then
raise “wrong version”
end

Of course, this can be wrapped into a nice version class. I wrote one
of these a long time ago and never released it, but there are plenty of
others already out there.

Paul

nice! you win paul!

Any one think Ruby needs a Tuple class?

-t0

···

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’ :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).

ah yes - did think of that at one point. must have drank more coffee that
day. thatnks for the heads up. definitely best to stick with a ‘to_f’ type
impl for now.

it would be really good if there was a ‘standard’ way to do this.

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

interface.age.revision

etc. etc.

does anyone know what the meaning of ruby’s tripplet?

-a

···

On Tue, 25 Nov 2003, Gennady wrote:

Date: Tue, 25 Nov 2003 14:56:03 +0900
From: Gennady bystr@mac.com
Newsgroups: comp.lang.ruby
Subject: Re: raise unless RUBY_VERSION[%r/^\s*\d+.\d+/o].to_f >= 1.8

On Nov 24, 2003, at 20:42, Ara.T.Howard wrote:

On Tue, 25 Nov 2003, Florian Gross wrote:

Date: Tue, 25 Nov 2003 08:54:02 +0900
From: Florian Gross flgr@ccan.de
Newsgroups: comp.lang.ruby
Subject: Re: raise unless RUBY_VERSION[%r/^\s*\d+.\d+/o].to_f >= 1.8

Moin!

Ara.T.Howard wrote:

any better methods of require a specific version/set of versions?

What about RUBY_VERSION >= “1.8.0”?

Regards,
Florian Gross

i thought about this for a while and came up with a good reason not to
do this

  • but it currently eludes me!

unless someone can think of a reason not to - i’ll take it!

It does not work as a general solution, as “1.11.0” < “1.8.0”. However,
bearing in mind that Ruby so far had only 1-digit version components
and 1.9.x is going to be the last Ruby1 version (according to Matz),
this check may be OK.

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

yes. one thing i had not yet mentioned is that i also may want to incorporate
the semantics of version. for instance, with libtool type versioning, the
following are compatible versions:

7.6.10
2.0.7

this is because, with libtool, the revision’s meaning is

revision.age.impl

(see the libtool docs for more)

because revision 7 spans 6 ages, it is compatible with all versions 1 - 7.

i don’t know what ruby’s major, minor, teeny numbers mean but would like to do
something similar if possible. and using them in paul’s way would make the
intent very clear.

-a

···

On Thu, 27 Nov 2003, T. Onoma wrote:

Date: Thu, 27 Nov 2003 14:59:58 +0900
From: T. Onoma transami@runbox.com
Newsgroups: comp.lang.ruby
Subject: Re: raise unless RUBY_VERSION[%r/^\s*\d+.\d+/o].to_f >= 1.8

On Thursday 27 November 2003 12:12 am, Ara.T.Howard wrote:

On Thu, 27 Nov 2003, Paul Brannan wrote:

Date: Thu, 27 Nov 2003 06:40:52 +0900
From: Paul Brannan pbrannan@atdesk.com
Newsgroups: comp.lang.ruby
Subject: Re: raise unless RUBY_VERSION[%r/^\s*\d+.\d+/o].to_f >= 1.8

On Tue, Nov 25, 2003 at 08:32:14AM +0900, Ara.T.Howard wrote:

any better methods of require a specific version/set of versions?

require ‘rbconfig’

major = Config::CONFIG[‘MAJOR’].to_i
minor = Config::CONFIG[‘MINOR’].to_i
teeny = Config::CONFIG[‘TEENY’].to_i
if major < 1 or (major == 1 and minor < 8) then
raise “wrong version”
end

Of course, this can be wrapped into a nice version class. I wrote one
of these a long time ago and never released it, but there are plenty of
others already out there.

Paul

nice! you win paul!

not knocking paul’s solution or anything, but you prefer this to using a
tuple?

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

“T. Onoma” transami@runbox.com 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’ :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.

robert

On Tue, 25 Nov 2003, Gennady wrote:

···

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

> Date: Tue, 25 Nov 2003 14:56:03 +0900

> From: Gennady bystr@mac.com

> Newsgroups: comp.lang.ruby

> Subject: Re: raise unless RUBY_VERSION[%r/^\s*\d+.\d+/o].to_f >= 1.8

>

>

>

> On Nov 24, 2003, at 20:42, Ara.T.Howard wrote:

>

> > On Tue, 25 Nov 2003, Florian Gross wrote:

> >

> >> Date: Tue, 25 Nov 2003 08:54:02 +0900

> >> From: Florian Gross flgr@ccan.de

> >> Newsgroups: comp.lang.ruby

> >> Subject: Re: raise unless RUBY_VERSION[%r/^\s*\d+.\d+/o].to_f >= 1.8

> >>

> >> Moin!

> >>

> >> Ara.T.Howard wrote:

> >>

> >>> any better methods of require a specific version/set of versions?

> >>

> >> What about RUBY_VERSION >= “1.8.0”?

> >>

> >> Regards,

> >> Florian Gross

> >

> > i thought about this for a while and came up with a good reason not to

> > do this

> > - but it currently eludes me!

> >

> > unless someone can think of a reason not to - i’ll take it!

>

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

> bearing in mind that Ruby so far had only 1-digit version components

> and 1.9.x is going to be the last Ruby1 version (according to Matz),

> this check may be OK.

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

day. thatnks for the heads up. definitely best to stick with a ‘to_f’ type

impl for now.

it would be really good if there was a ‘standard’ way to do this.

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.

Chad

Unfortunately, ‘to_f’ suffers the same problem, since 1.11 < 1.8.
Numerically compare each part of version string:

require ‘scanf.rb’
raise unless (RUBY_VERSION.scanf(“%d.%d.%d”) <=> [1,8]) >= 0

···

“Ara.T.Howard” ahoward@ngdc.noaa.gov wrote:

On Tue, 25 Nov 2003, Gennady wrote:

On Tue, 25 Nov 2003, Florian Gross wrote:

What about RUBY_VERSION >= “1.8.0”?

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

ah yes - did think of that at one point. must have drank more coffee that
day. thatnks for the heads up. definitely best to stick with a ‘to_f’ type
impl for now.

No,

class Tuple < Array
include Comparable
end

class Array
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.

-t0

···

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

“T. Onoma” transami@runbox.com 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’ :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.