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.



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

#secondObject

Returns the second item in the array

Returns:

  • (Object)

    the second item in the array



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

def second; self[1]; end

#short_hexObject Also known as: short



591
592
593
# File 'lib/amp/support/support.rb', line 591

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

#sumArray

Sums all the items in the array

Returns:

  • (Array)

    the items summed



566
567
568
# File 'lib/amp/support/support.rb', line 566

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

#to_hashObject



587
588
589
# File 'lib/amp/support/support.rb', line 587

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