Class: SortedArray
Instance Method Summary collapse
- #<<(v) ⇒ Object (also: #push, #unshift)
- 
  
    
      #initialize(*args, &sort_by)  ⇒ SortedArray 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of SortedArray. 
- #insert(_i, v) ⇒ Object
Methods inherited from Array
Constructor Details
#initialize(*args, &sort_by) ⇒ SortedArray
Returns a new instance of SortedArray.
| 2 3 4 5 6 | # File 'lib/gepub/sorted_array.rb', line 2 def initialize(*args, &sort_by) @sort_by = sort_by || Proc.new { |x,y| x <=> y } super(*args) self.sort!() &sort_by end | 
Instance Method Details
#<<(v) ⇒ Object Also known as: push, unshift
| 13 14 15 | # File 'lib/gepub/sorted_array.rb', line 13 def <<(v) insert(0, v) end | 
#insert(_i, v) ⇒ Object
| 8 9 10 11 | # File 'lib/gepub/sorted_array.rb', line 8 def insert(_i, v) insert_before = index(find { |x| @sort_by.call(x, v) == 1 }) super(insert_before ? insert_before : -1, v) end |