Class: Array
Instance Method Summary collapse
-
#delete_range(range) ⇒ Object
Deletes the given range from the array, in-place.
-
#second ⇒ Object
Returns the second item in the array.
- #short_hex ⇒ Object (also: #short)
-
#sum ⇒ Array
Sums all the items in the array.
- #to_hash ⇒ Object
Instance Method Details
#delete_range(range) ⇒ Object
Deletes the given range from the array, in-place.
577 578 579 580 581 582 583 584 585 |
# File 'lib/amp/support/support.rb', line 577 def delete_range(range) newend = (range.end < 0) ? self.size + range.end : range.end newbegin = (range.begin < 0) ? self.size + range.begin : range.begin newrange = Range.new newbegin, newend pos = newrange.first newrange.each {|i| self.delete_at pos } self end |
#second ⇒ Object
Returns the second item in the array
574 |
# File 'lib/amp/support/support.rb', line 574 def second; self[1]; end |
#short_hex ⇒ Object Also known as: short
591 592 593 |
# File 'lib/amp/support/support.rb', line 591 def short_hex map {|e| e.short_hex } end |
#sum ⇒ Array
Sums all the items in the array
566 567 568 |
# File 'lib/amp/support/support.rb', line 566 def sum inject(0) {|sum, x| sum + x } end |
#to_hash ⇒ Object
587 588 589 |
# File 'lib/amp/support/support.rb', line 587 def to_hash inject({}) {|h, (k, v)| h.merge k => v } end |