Commit cf588bd5 authored by go.kikuta's avatar go.kikuta

range.rb: refactor code (use ! instead of not, use favor modifier if and...

range.rb: refactor code (use ! instead of not, use favor modifier if and unless usage when having a single-line body)
parent 71f2975a
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment