mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
range.rb: refactor code (use ! instead of not, use favor modifier if and unless usage when having a single-line body)
This commit is contained in:
+3
-9
@@ -26,9 +26,7 @@ class Range
|
||||
return self
|
||||
end
|
||||
|
||||
unless val.respond_to? :succ
|
||||
raise TypeError, "can't iterate"
|
||||
end
|
||||
raise TypeError, "can't iterate" unless val.respond_to? :succ
|
||||
|
||||
return self if (val <=> last) > 0
|
||||
|
||||
@@ -37,18 +35,14 @@ class Range
|
||||
val = val.succ
|
||||
end
|
||||
|
||||
if not exclude_end? and (val <=> last) == 0
|
||||
block.call(val)
|
||||
end
|
||||
block.call(val) if !exclude_end? && (val <=> last) == 0
|
||||
self
|
||||
end
|
||||
|
||||
# redefine #hash 15.3.1.3.15
|
||||
def hash
|
||||
h = first.hash ^ last.hash
|
||||
if self.exclude_end?
|
||||
h += 1
|
||||
end
|
||||
h += 1 if self.exclude_end?
|
||||
h
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user