mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Fixes the twiddle wakka comparison algorithm to support passing only a major number
This commit is contained in:
+6
-4
@@ -267,16 +267,18 @@ module MRuby
|
||||
# ~> compare algorithm
|
||||
#
|
||||
# Example:
|
||||
# ~> 2 means >= 2.0.0 and < 3.0.0
|
||||
# ~> 2.2 means >= 2.2.0 and < 3.0.0
|
||||
# ~> 2.2.0 means >= 2.2.0 and < 2.3.0
|
||||
# ~> 2.2.2 means >= 2.2.2 and < 2.3.0
|
||||
def twiddle_wakka_ok?(other)
|
||||
gr_or_eql = (self <=> other) >= 0
|
||||
still_minor = (self <=> other.skip_minor) < 0
|
||||
gr_or_eql and still_minor
|
||||
still_major_or_minor = (self <=> other.skip_major_or_minor) < 0
|
||||
gr_or_eql and still_major_or_minor
|
||||
end
|
||||
|
||||
def skip_minor
|
||||
def skip_major_or_minor
|
||||
a = @ary.dup
|
||||
a << 0 if a.size == 1 # ~> 2 can also be represented as ~> 2.0
|
||||
a.slice!(-1)
|
||||
a[-1] = a[-1].succ
|
||||
a
|
||||
|
||||
Reference in New Issue
Block a user