class SortedArray

Public Class Methods

new(*args, &sort_by) click to toggle source
Calls superclass method
# 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

Public Instance Methods

<<(v) click to toggle source
# File lib/gepub/sorted_array.rb, line 13
def <<(v)
  insert(0, v)
end
Also aliased as: push, unshift
insert(_i, v) click to toggle source
Calls superclass method
# 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
push(v)
Alias for: <<
unshift(v)
Alias for: <<