[RCR] meaningful RUBY_VERSION#<=>

A

Ara.T.Howard

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
 
M

Mauricio Fernandez

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
 
A

ara.t.howard

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

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

-a
 
G

George Ogata

Mauricio Fernandez said:
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 :-(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top