[RCR] meaningful RUBY_VERSION#<=>

Discussion in 'Ruby' started by Ara.T.Howard, Feb 2, 2006.

  1. Ara.T.Howard

    Ara.T.Howard Guest

    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
     
    Ara.T.Howard, Feb 2, 2006
    #1
    1. Advertising

  2. 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
     
    Mauricio Fernandez, Feb 2, 2006
    #2
    1. Advertising

  3. Ara.T.Howard

    Guest

    On Fri, 3 Feb 2006, Mauricio Fernandez wrote:

    > 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


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

    -a

    --
    happiness is not something ready-made. it comes from your own actions.
    - h.h. the 14th dali lama
     
    , Feb 2, 2006
    #3
  4. Ara.T.Howard

    George Ogata Guest

    Mauricio Fernandez <> 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 :-(
     
    George Ogata, Feb 3, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. walala
    Replies:
    1
    Views:
    1,258
    Mike Treseler
    Aug 11, 2003
  2. Joshua Ellul
    Replies:
    0
    Views:
    344
    Joshua Ellul
    Feb 15, 2004
  3. Khalid Sheikh
    Replies:
    1
    Views:
    424
    Dennis Lee Bieber
    Jul 19, 2003
  4. supercooper
    Replies:
    1
    Views:
    319
    Grant Edwards
    Jun 13, 2007
  5. Replies:
    3
    Views:
    323
    Thad Smith
    Feb 29, 2008
Loading...

Share This Page