summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-enumerator/mrblib/enumerator.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2014-03-15 11:35:02 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2014-03-15 11:35:02 +0900
commitfc75cff14e7d43defb0c99f5bc9d657c0121c4b0 (patch)
tree80aadc6687bf7a61e8e75d46bc50c7b77143ca18 /mrbgems/mruby-enumerator/mrblib/enumerator.rb
parente893349e95259dd7902048928525e30352478c7d (diff)
parent447764763cd2608cbd47954f98113edd71b5e801 (diff)
downloadmruby-fc75cff14e7d43defb0c99f5bc9d657c0121c4b0.tar.gz
mruby-fc75cff14e7d43defb0c99f5bc9d657c0121c4b0.zip
Merge pull request #1859 from ksss/enumerator
Fix Enumerator
Diffstat (limited to 'mrbgems/mruby-enumerator/mrblib/enumerator.rb')
-rw-r--r--mrbgems/mruby-enumerator/mrblib/enumerator.rb20
1 files changed, 13 insertions, 7 deletions
diff --git a/mrbgems/mruby-enumerator/mrblib/enumerator.rb b/mrbgems/mruby-enumerator/mrblib/enumerator.rb
index 176ae661c..912683ed9 100644
--- a/mrbgems/mruby-enumerator/mrblib/enumerator.rb
+++ b/mrbgems/mruby-enumerator/mrblib/enumerator.rb
@@ -156,10 +156,10 @@ class Enumerator
return to_enum :with_index, offset unless block_given?
raise TypeError, "no implicit conversion of #{offset.class} into Integer" unless offset.respond_to?(:to_int)
- n = offset.to_int
- each do |i|
- yield [i,n]
+ n = offset.to_int - 1
+ enumerator_block_call do |i|
n += 1
+ yield [i,n]
end
end
@@ -206,9 +206,9 @@ class Enumerator
# # => foo:2
#
def with_object object
- return to_enum :with_object, offset unless block_given?
+ return to_enum :with_object, object unless block_given?
- each do |i|
+ enumerator_block_call do |i|
yield [i,object]
end
object
@@ -255,6 +255,7 @@ class Enumerator
# enum.each(:y, :z) { |elm| elm } #=> :method_returned
#
def each *argv, &block
+ obj = self
if 0 < argv.length
obj = self.dup
args = obj.args
@@ -264,11 +265,16 @@ class Enumerator
else
args = argv.dup
end
- @args = args
+ obj.args = args
end
- return self unless block_given?
+ return obj unless block_given?
+ enumerator_block_call(&block)
+ end
+
+ def enumerator_block_call(&block)
@obj.__send__ @meth, *@args, &block
end
+ private :enumerator_block_call
##
# call-seq: