Module: RubyVersion

Extended by:
Comparable
Defined in:
lib/ruby_version.rb,
lib/ruby_version/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.<=>(other) ⇒ Object

comparable



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ruby_version.rb', line 12

def <=>(other)
  value = case other
    when Integer
      RUBY_VERSION.to_i
    when Float
      RUBY_VERSION.to_f
    when String
      RUBY_VERSION
    when Date, Time
      other.class.parse(RUBY_RELEASE_DATE)
    else
      other = other.to_s
      RUBY_VERSION
    end
  value <=> other
end

.descriptionObject



112
113
114
# File 'lib/ruby_version.rb', line 112

def description
  RUBY_DESCRIPTION
end

.is?(other = nil) ⇒ Boolean Also known as: is

chaining for dsl-like language

Returns:

  • (Boolean)


31
32
33
34
35
36
37
# File 'lib/ruby_version.rb', line 31

def is?(other = nil)
  if other
    RubyVersion == other
  else
    RubyVersion
  end
end

.majorObject Also known as: main

accessors



83
84
85
# File 'lib/ruby_version.rb', line 83

def major
  RUBY_VERSION.to_i
end

.minorObject Also known as: mini



88
89
90
# File 'lib/ruby_version.rb', line 88

def minor
  RUBY_VERSION.split('.')[1].to_i
end

.newer_than(other) ⇒ Object Also known as: newer_than?

compare dates



58
59
60
61
62
63
64
# File 'lib/ruby_version.rb', line 58

def newer_than(other)
  if other.is_a? Date or other.is_a? Time
    RubyVersion > other
  else
    RUBY_RELEASE_DATE > other.to_s
  end
end

.not(other) ⇒ Object Also known as: not?



51
52
53
# File 'lib/ruby_version.rb', line 51

def not(other)
  self != other
end

.older_than(other) ⇒ Object Also known as: older_than?



67
68
69
70
71
72
73
# File 'lib/ruby_version.rb', line 67

def older_than(other)
  if other.is_a? Date or other.is_a? Time
    RubyVersion < other
  else
    RUBY_RELEASE_DATE < other.to_s
  end
end

.patchlevelObject



99
100
101
# File 'lib/ruby_version.rb', line 99

def patchlevel
  RUBY_PATCHLEVEL
end

.platformObject



103
104
105
# File 'lib/ruby_version.rb', line 103

def platform
  RUBY_PLATFORM
end

.release_dateObject Also known as: date



107
108
109
# File 'lib/ruby_version.rb', line 107

def release_date
  Date.parse RUBY_RELEASE_DATE
end

.released_todayObject Also known as: released_today?



76
77
78
# File 'lib/ruby_version.rb', line 76

def released_today
  RubyVersion.date == Date.today
end

.tinyObject Also known as: teeny



93
94
95
# File 'lib/ruby_version.rb', line 93

def tiny
  RUBY_VERSION.split('.')[2].to_i
end

.to_sObject Also known as: inspect



6
7
8
# File 'lib/ruby_version.rb', line 6

def to_s
  RUBY_VERSION
end