Class: Enumerator

Inherits:
Object show all
Defined in:
lib/tagen/core/enumerator.rb

Instance Method Summary collapse

Instance Method Details

#with_iobject(*args) ⇒ Object #with_iobject(*args) {|(*args), idx, memo_obj| ... } ⇒ Object

combine with_index and with_object

Examples:

(1..7).each.with_iobject([]){|(*args), idx, memo|}
(1..7).each.with_iobject(2, []){|(*args), idx, memo|} # offset is 2

Overloads:

  • #with_iobject(*args) ⇒ Object

    Returns Enumerator.

    Parameters:

    • *args (Fixnum, Object)

      pass Fixnum as offset, otherwise as memo_obj

    Returns:

    • Enumerator

  • #with_iobject(*args) {|(*args), idx, memo_obj| ... } ⇒ Object

    Yield Parameters:

See Also:

  • with_object


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/tagen/core/enumerator.rb', line 17

def with_iobject *args, &blk
	return self.to_enum(:with_iobject, *args) unless blk

	offset = args.find!{|v| Fixnum===v} || 0
	raise ArgumentError "must provide memo_obj" if args.empty?
	memo = args[0]

	i = offset-1
	self.with_object memo do |args, m|
		blk.call args,i+=1,m
	end
end