Class: Array

Inherits:
Object show all
Defined in:
lib/amp/support/support.rb

Instance Method Summary collapse

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

#secondObject

Returns the second item in the array

Returns:

  • (Object)

    the second item in the array



576
# File 'lib/amp/support/support.rb', line 576

def second; self[1]; end

#short_hexObject Also known as: short



593
594
595
# File 'lib/amp/support/support.rb', line 593

def short_hex
  map {|e| e.short_hex }
end

#sumArray

Sums all the items in the array

Returns:

  • (Array)

    the items summed



568
569
570
# File 'lib/amp/support/support.rb', line 568

def sum
  inject(0) {|sum, x| sum + x }
end

#to_hashObject



589
590
591
# File 'lib/amp/support/support.rb', line 589

def to_hash
  inject({}) {|h, (k, v)| h.merge k => v }
end