-
Notifications
You must be signed in to change notification settings - Fork 1
/
ruby_version.rb
87 lines (58 loc) · 1.6 KB
/
ruby_version.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
##
# Methods to work with the current ruby version at the MAJOR.MINOR level
#
module RubyVersion
class << self
# Returns the latest known version of Ruby
def latest_version
Gem::Version.new('3.3')
end
# Returns true if the current verion of Ruby is as defined
def latest?
is?(latest_version)
end
# Returns tru if the current version of Ruby matches the expected version
#
# expected: anything that can be stringified with String(xxx)
#
def is?(expected = nil)
expected = refined(expected)
expected == current
end
# Return a Gem::Version of the current Ruby version twith only MJOR.MINOR segments
def current
@current_version ||= refined RUBY_VERSION
end
def ==(other)
current == refined(other)
end
def >(other)
current > refined(other)
end
def >=(other)
current >= refined(other)
end
def <(other)
current < refined(other)
end
def <=(other)
current <= refined(other)
end
# Returns the string filename for the current ruby version gemfile
def gemfile
"ruby_#{current.to_s.gsub('.','_')}.gemfile"
end
# ======================================================================
# = Private
# ======================================================================
# Return a Gem::Version from the given version refined down to MAJOR.MINOR segments
#
# version: anything that can be stringified with String(xxx)
#
def refined(version)
version = String(version)
refined_version = Gem::Version.new(version).release.segments[0..1].join('.')
Gem::Version.new(refined_version)
end
end
end