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.
579 580 581 582 583 584 585 586 587 |
# File 'lib/amp/support/support.rb', line 579 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
576 |
# File 'lib/amp/support/support.rb', line 576 def second; self[1]; end |
#short_hex ⇒ Object Also known as: short
593 594 595 |
# File 'lib/amp/support/support.rb', line 593 def short_hex map {|e| e.short_hex } end |
#sum ⇒ Array
Sums all the items in the array
568 569 570 |
# File 'lib/amp/support/support.rb', line 568 def sum inject(0) {|sum, x| sum + x } end |
#to_hash ⇒ Object
589 590 591 |
# File 'lib/amp/support/support.rb', line 589 def to_hash inject({}) {|h, (k, v)| h.merge k => v } end |