- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-enumerator/mrblib/enumerator.rb
r321 r331 154 154 def with_index(offset=0) 155 155 return to_enum :with_index, offset unless block_given? 156 raise TypeError, "no implicit conversion of #{offset.class} into Integer" unless offset.respond_to?(:to_int) 157 158 n = offset.to_int - 1 159 enumerator_block_call do |i| 156 offset = if offset.nil? 157 0 158 elsif offset.respond_to?(:to_int) 159 offset.to_int 160 else 161 raise TypeError, "no implicit conversion of #{offset.class} into Integer" 162 end 163 164 n = offset - 1 165 enumerator_block_call do |*i| 160 166 n += 1 161 yield [i,n]167 yield i.__svalue, n 162 168 end 163 169 end … … 172 178 # If no block is given, a new Enumerator is returned that includes the index. 173 179 # 174 def each_with_index 175 with_index 180 def each_with_index(&block) 181 with_index(0, &block) 176 182 end 177 183 … … 517 523 # just for internal 518 524 class Generator 525 include Enumerable 519 526 def initialize(&block) 520 527 raise TypeError, "wrong argument type #{self.class} (expected Proc)" unless block.kind_of? Proc
Note:
See TracChangeset
for help on using the changeset viewer.