Module: Ruby::Version

Defined in:
lib/ruby-version.rb

Overview

Wraps the RUBY_VERSION constant and provides some handling such as comparing.

Constant Summary collapse

VERSION =

Contains the Ruby version identification in frozen string. It’s content is equal to the RUBY_VERSION constant.

RUBY_VERSION.dup.freeze
TOKENS =

Contents frozen tokens array of the current ruby version.

See Also:

self::broke(self::VERSION).freeze

Class Method Summary collapse

Class Method Details

.<(value) ⇒ Boolean

Lower operator.

Parameters:

  • value (String, Symbol, Array)

    version identifier

Returns:

  • (Boolean)

    true if yes, +false otherwise



93
94
95
96
97
# File 'lib/ruby-version.rb', line 93

def self.<(value)
    __cache(:<, value) do
        __compare(value, true, false, false)
    end
end

.<=(value) ⇒ Boolean

Lower or equal operator.

Parameters:

  • value (String, Symbol, Array)

    version identifier

Returns:

  • (Boolean)

    true if yes, +false otherwise



80
81
82
83
84
# File 'lib/ruby-version.rb', line 80

def self.<=(value)
    __cache(:"<=", value) do
        __compare(value, true, false, true)
    end
end

.<=>(value) ⇒ Boolean

Alias for #compare.

Parameters:

  • value (String, Symbol, Array)

    version identifier

Returns:

  • (Boolean)

    1 if this one is higher, -1 if lower and 0 otherwise



145
146
147
# File 'lib/ruby-version.rb', line 145

def self.<=>(value)
    self.compare(value)
end

.==(value) ⇒ Boolean

Equality operator.

Parameters:

  • value (String, Symbol, Array)

    version identifier

Returns:

  • (Boolean)

    true if yes, +false otherwise



119
120
121
122
123
# File 'lib/ruby-version.rb', line 119

def self.==(value)
    __cache(:"==", value) do
        __compare(value, false, false, true)
    end
end

.>(value) ⇒ Boolean

Higher operator.

Parameters:

  • value (String, Symbol, Array)

    version identifier

Returns:

  • (Boolean)

    true if yes, +false otherwise



106
107
108
109
110
# File 'lib/ruby-version.rb', line 106

def self.>(value)
    __cache(:>, value) do
        __compare(value, false, true, false)
    end
end

.>=(value) ⇒ Boolean

Higher or equal operator.

Parameters:

  • value (String, Symbol, Array)

    version identifier

Returns:

  • (Boolean)

    true if yes, +false otherwise



67
68
69
70
71
# File 'lib/ruby-version.rb', line 67

def self.>=(value)
    __cache(:">=", value) do
        __compare(value, false, true, true)
    end
end

.broke(string) ⇒ Array

Brokes string identifier to numeric tokens in array.

Parameters:

  • value (String, Symbol)

    version identifier

Returns:

  • (Array)

    array of tokens



156
157
158
# File 'lib/ruby-version.rb', line 156

def self.broke(string)
    string.to_s.split(".").map! { |i| i.to_i }
end

.compare(value) ⇒ Boolean

Compares version strings.

Parameters:

  • value (String, Symbol, Array)

    version identifier

Returns:

  • (Boolean)

    1 if this one is higher, -1 if lower and 0 otherwise



132
133
134
135
136
# File 'lib/ruby-version.rb', line 132

def self.compare(value)
    __cache(:compare, value) do
        __compare(value, -1, 1, 0)
    end
end