mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-compar-ext/compar.rb (clamp): support endless/beginless range.
Ref #5748
This commit is contained in:
@@ -14,11 +14,16 @@ module Comparable
|
||||
def clamp(min, max=nil)
|
||||
if max.nil?
|
||||
if min.kind_of?(Range)
|
||||
if min.exclude_end?
|
||||
max = min.begin
|
||||
if max.nil?
|
||||
max = self
|
||||
elsif min.exclude_end?
|
||||
raise ArgumentError, "cannot clamp with an exclusive range"
|
||||
end
|
||||
max = min.max
|
||||
min = min.min
|
||||
min = min.end
|
||||
if min.nil?
|
||||
min = self
|
||||
end
|
||||
else
|
||||
raise TypeError, "wrong argument type #{min.class}"
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user