Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/tagen/core/array/append.rb,
lib/tagen/core/array/delete_values.rb,
lib/tagen/core/array/extract_options.rb

Instance Method Summary collapse

Instance Method Details

#delete_values(*values, &blk) ⇒ Object

See Also:

  • #delete


12
13
14
15
16
# File 'lib/tagen/core/array/delete_values.rb', line 12

def delete_values(*values, &blk)
	values.each.with_object([]) {|v,m|
		m << delete(v, &blk)
   }
end

#delete_values_at(*indexs, &blk) ⇒ Object

See Also:

  • #delete_at


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tagen/core/array/delete_values.rb', line 28

def delete_values_at(*indexs, &blk)
   offset = 0

   # convert to positve index
   indexs.map { |i| i < 0 ? length + i : i }

	indexs.each.with_object([]) {|i,m|
     if i > length
       m << nil
     else
       m << delete_at(i-offset, &blk)
       offset += 1
     end
   }
end

#extract_options(default = {}) ⇒ Array<Array,Hash>

Returns:

See Also:



16
17
18
19
20
21
22
# File 'lib/tagen/core/array/extract_options.rb', line 16

def extract_options(default={})
   if last.is_a?(Hash) && last.extractable_options?
		[self[0...-1], default.merge(self[-1])]
	else
		[self, default]
	end
end

#extract_options!(default = {}) ⇒ Hash

Parameters:

  • default (Hash) (defaults to: {})

    default options

Returns:

  • (Hash)


38
39
40
41
42
43
44
# File 'lib/tagen/core/array/extract_options.rb', line 38

def extract_options!(default={})
   if last.is_a?(Hash) && last.extractable_options?
     default.merge pop
   else
     default
   end
end