Module: RubyVersion

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

Constant Summary collapse

VERSION =
'1.0.1'

Class Method Summary collapse

Class Method Details

.<=>(other) ⇒ Object

comparable



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

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



114
115
116
# File 'lib/ruby_version.rb', line 114

def description
  RUBY_DESCRIPTION
end

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

chaining for dsl-like language

Returns:

  • (Boolean)


33
34
35
36
37
38
39
# File 'lib/ruby_version.rb', line 33

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

.majorObject Also known as: main

accessors



85
86
87
# File 'lib/ruby_version.rb', line 85

def major
  RUBY_VERSION.to_i
end

.minorObject Also known as: mini



90
91
92
# File 'lib/ruby_version.rb', line 90

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

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

compare dates



60
61
62
63
64
65
66
# File 'lib/ruby_version.rb', line 60

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?



53
54
55
# File 'lib/ruby_version.rb', line 53

def not(other)
  self != other
end

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



69
70
71
72
73
74
75
# File 'lib/ruby_version.rb', line 69

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



101
102
103
# File 'lib/ruby_version.rb', line 101

def patchlevel
  RUBY_PATCHLEVEL
end

.platformObject



105
106
107
# File 'lib/ruby_version.rb', line 105

def platform
  RUBY_PLATFORM
end

.release_dateObject Also known as: date



109
110
111
# File 'lib/ruby_version.rb', line 109

def release_date
  Date.parse RUBY_RELEASE_DATE
end

.released_todayObject Also known as: released_today?



78
79
80
# File 'lib/ruby_version.rb', line 78

def released_today
  RubyVersion.date == Date.today
end

.revisionObject



118
119
120
# File 'lib/ruby_version.rb', line 118

def revision
  defined?(RUBY_REVISION) && RUBY_REVISION
end

.tinyObject Also known as: teeny



95
96
97
# File 'lib/ruby_version.rb', line 95

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

.to_sObject Also known as: inspect



8
9
10
# File 'lib/ruby_version.rb', line 8

def to_s
  RUBY_VERSION
end