Forum: Ruby meaningful RUBY_VERSION#<=>

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ara.T.Howard (Guest)
on 2006-02-02 22:30
(Received via mailing list)
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
Mauricio F. (Guest)
on 2006-02-02 23:09
(Received via mailing list)
On Fri, Feb 03, 2006 at 05:29:10AM +0900, Ara.T.Howard wrote:
>
>   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
unknown (Guest)
on 2006-02-02 23:33
(Received via mailing list)
On Fri, 3 Feb 2006, Mauricio F. wrote:

>>   end
> 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
George O. (Guest)
on 2006-02-03 15:05
(Received via mailing list)
Mauricio F. <removed_email_address@domain.invalid> 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  :-(
This topic is locked and can not be replied to.