Sha256: e34188e24ab7783945ef83aa9b38c32ddcf3b4e4b82ddf4297c3ede37316627f

Contents?: true

Size: 380 Bytes

Versions: 16

Compression:

Stored size: 380 Bytes

Contents

class SortedArray < Array
  def initialize(*args, &sort_by)
    @sort_by = sort_by || Proc.new { |x,y| x <=> y }
    super(*args)
    self.sort!() &sort_by
  end

  def insert(_i, v)
    insert_before = index(find { |x| @sort_by.call(x, v) == 1 })
    super(insert_before ? insert_before : -1, v)
  end

  def <<(v)
    insert(0, v)
  end

  alias push <<
  alias unshift <<

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
gepub-1.0.16 lib/gepub/sorted_array.rb
gepub-1.0.15 lib/gepub/sorted_array.rb
gepub-1.0.14 lib/gepub/sorted_array.rb
gepub-1.0.13 lib/gepub/sorted_array.rb
gepub-1.0.12 lib/gepub/sorted_array.rb
gepub-1.0.11 lib/gepub/sorted_array.rb
gepub-1.0.10 lib/gepub/sorted_array.rb
gepub-1.0.9 lib/gepub/sorted_array.rb
gepub-1.0.8 lib/gepub/sorted_array.rb
gepub-1.0.7 lib/gepub/sorted_array.rb
gepub-1.0.6 lib/gepub/sorted_array.rb
gepub-1.0.5 lib/gepub/sorted_array.rb
gepub-1.0.4 lib/gepub/sorted_array.rb
gepub-1.0.3 lib/gepub/sorted_array.rb
gepub-1.0.2 lib/gepub/sorted_array.rb
gepub-1.0.1 lib/gepub/sorted_array.rb