diff options
Diffstat (limited to 'mrbgems/mruby-enumerator/mrblib/enumerator.rb')
| -rw-r--r-- | mrbgems/mruby-enumerator/mrblib/enumerator.rb | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/mrbgems/mruby-enumerator/mrblib/enumerator.rb b/mrbgems/mruby-enumerator/mrblib/enumerator.rb index a60f19aaf..c872ceedc 100644 --- a/mrbgems/mruby-enumerator/mrblib/enumerator.rb +++ b/mrbgems/mruby-enumerator/mrblib/enumerator.rb @@ -110,7 +110,7 @@ class Enumerator # p fib.take(10) # => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] # def initialize(obj=nil, meth=:each, *args, &block) - if block_given? + if block obj = Generator.new(&block) else raise ArgumentError unless obj @@ -151,8 +151,9 @@ class Enumerator # # +offset+:: the starting index to use # - def with_index(offset=0) - return to_enum :with_index, offset unless block_given? + def with_index(offset=0, &block) + return to_enum :with_index, offset unless block + offset = if offset.nil? 0 elsif offset.respond_to?(:to_int) @@ -164,7 +165,7 @@ class Enumerator n = offset - 1 enumerator_block_call do |*i| n += 1 - yield i.__svalue, n + block.call i.__svalue, n end end @@ -209,11 +210,11 @@ class Enumerator # # => foo:1 # # => foo:2 # - def with_object(object) - return to_enum(:with_object, object) unless block_given? + def with_object(object, &block) + return to_enum(:with_object, object) unless block enumerator_block_call do |i| - yield [i,object] + block.call [i,object] end object end @@ -277,7 +278,7 @@ class Enumerator end obj.args = args end - return obj unless block_given? + return obj unless block enumerator_block_call(&block) end @@ -538,7 +539,7 @@ class Enumerator # just for internal class Yielder def initialize(&block) - raise LocalJumpError, "no block given" unless block_given? + raise LocalJumpError, "no block given" unless block @proc = block end |
