Class: Array
- Inherits:
-
Object
- Object
- Array
- 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
- #delete_values(*values, &blk) ⇒ Object
- #delete_values_at(*indexs, &blk) ⇒ Object
- #extract_options(default = {}) ⇒ Array<Array,Hash>
- #extract_options!(default = {}) ⇒ Hash
Instance Method Details
#delete_values(*values, &blk) ⇒ Object
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
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>
16 17 18 19 20 21 22 |
# File 'lib/tagen/core/array/extract_options.rb', line 16 def (default={}) if last.is_a?(Hash) && last. [self[0...-1], default.merge(self[-1])] else [self, default] end end |
#extract_options!(default = {}) ⇒ Hash
38 39 40 41 42 43 44 |
# File 'lib/tagen/core/array/extract_options.rb', line 38 def (default={}) if last.is_a?(Hash) && last. default.merge pop else default end end |