Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[RCR] meaningful RUBY_VERSION#<=>

0 views
Skip to first unread message

Ara.T.Howard

unread,
Feb 2, 2006, 3:29:10 PM2/2/06
to

i'm sure something much more elegant could be made, but this summarizes desired
behaviour.


harp:~ > cat a.rb
class RubyVersion < ::String
include Comparable
def <=> other
components <=> RubyVersion::new(other).components
end
def components
scan(%r/\d+/).map{|c| Integer c}
end
def major
components[0]
end
def minor
components[1]
end
def tiny
components[2]
end
module ::Kernel
def RubyVersion *a, &b
RubyVersion::new *a, &b
end
v = $VERBOSE
$VERBOSE = nil
::RUBY_VERSION = RubyVersion(::RUBY_VERSION)
$VERBOSE = v
end
end

p RUBY_VERSION
p RUBY_VERSION > "1.8.3"
p RUBY_VERSION > "1.9.0"


harp:~ > ruby a.rb
"1.8.4"
true
false


kind regards.

-a

--
happiness is not something ready-made. it comes from your own actions.
- h.h. the 14th dali lama


Mauricio Fernandez

unread,
Feb 2, 2006, 4:09:06 PM2/2/06
to
On Fri, Feb 03, 2006 at 05:29:10AM +0900, Ara.T.Howard wrote:
> module ::Kernel
> def RubyVersion *a, &b
> RubyVersion::new *a, &b
> end
> v = $VERBOSE
> $VERBOSE = nil
> ::RUBY_VERSION = RubyVersion(::RUBY_VERSION)
> $VERBOSE = v
> end
> end
>
> p RUBY_VERSION
> p RUBY_VERSION > "1.8.3"
> p RUBY_VERSION > "1.9.0"
>
> harp:~ > ruby a.rb
> "1.8.4"
> true
> false

matz has said that 1.8.10 (or more generally versions with 2 digits in one
of the components) will not happen. Isn't String#<=> enough? (unless you
absolutely want major, minor & tiny)

On a stock install:

RUBY_VERSION # => "1.8.4"
RUBY_VERSION > "1.8.3" # => true
RUBY_VERSION > "1.9.0" # => false


--
Mauricio Fernandez


ara.t....@noaa.gov

unread,
Feb 2, 2006, 4:32:41 PM2/2/06
to

maybe so then - i did not know about the 2 digit restriction. thanks!

George Ogata

unread,
Feb 3, 2006, 7:59:15 AM2/3/06
to
Mauricio Fernandez <m...@acm.org> writes:

> matz has said that 1.8.10 (or more generally versions with 2 digits in one
> of the components) will not happen.

Aww... I was really looking forward to ruby 10.0 :-(

0 new messages