diff options
| author | go.kikuta <[email protected]> | 2015-08-20 17:28:34 +0900 |
|---|---|---|
| committer | go.kikuta <[email protected]> | 2015-08-21 14:54:00 +0900 |
| commit | cf588bd5cb094e6ee22d8d45c2005cf0da55d197 (patch) | |
| tree | 122a1fcdfe16f633a392ac4cd58e62167eeffd10 | |
| parent | 71f2975a5ba93197fac6a08f21d84bc87e31c6ae (diff) | |
| download | mruby-cf588bd5cb094e6ee22d8d45c2005cf0da55d197.tar.gz mruby-cf588bd5cb094e6ee22d8d45c2005cf0da55d197.zip | |
range.rb: refactor code (use ! instead of not, use favor modifier if and unless usage when having a single-line body)
| -rw-r--r-- | mrblib/range.rb | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/mrblib/range.rb b/mrblib/range.rb index 64fa0cb6c..5e5fd9bdc 100644 --- a/mrblib/range.rb +++ b/mrblib/range.rb @@ -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 |
