diff options
| author | Jun Hiroe <[email protected]> | 2015-12-26 08:21:27 +0900 |
|---|---|---|
| committer | Jun Hiroe <[email protected]> | 2015-12-26 10:12:01 +0900 |
| commit | 88076901fda5edd312b198c89493a39e4c840ade (patch) | |
| tree | 9d3365d46dc96365a01302020d2c24913f0e480c /mrblib | |
| parent | a060bd51145c0db3e64bdc494307621024dae3ed (diff) | |
| download | mruby-88076901fda5edd312b198c89493a39e4c840ade.tar.gz mruby-88076901fda5edd312b198c89493a39e4c840ade.zip | |
Refactor Array#each
Diffstat (limited to 'mrblib')
| -rw-r--r-- | mrblib/array.rb | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/mrblib/array.rb b/mrblib/array.rb index 20174419e..d5a2d8405 100644 --- a/mrblib/array.rb +++ b/mrblib/array.rb @@ -12,13 +12,10 @@ class Array def each(&block) return to_enum :each unless block_given? - idx, length = -1, self.length-1 - while idx < length and length <= self.length and length = self.length-1 - elm = self[idx += 1] - if elm.nil? and length >= self.length - break - end - block.call(elm) + idx = 0 + while idx < length + block.call(self[idx]) + idx += 1 end self end |
