Sha256: 38c863389ad7db910933c8f99ac79218f68138a1d77f6a1577da26b9bc9f347d

Contents?: true

Size: 379 Bytes

Versions: 16

Compression:

Stored size: 379 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.0 lib/gepub/sorted_array.rb
gepub-1.0.0rc1 lib/gepub/sorted_array.rb
gepub-1.0.0beta1 lib/gepub/sorted_array.rb
gepub-0.7.1 lib/gepub/sorted_array.rb
gepub-0.7.0 lib/gepub/sorted_array.rb
gepub-0.7.0beta4 lib/gepub/sorted_array.rb
gepub-0.7.0beta3 lib/gepub/sorted_array.rb
gepub-0.7.0beta2 lib/gepub/sorted_array.rb
gepub-0.7.0beta1 lib/gepub/sorted_array.rb
gepub-0.6.9.2 lib/gepub/sorted_array.rb
gepub-0.6.9.1 lib/gepub/sorted_array.rb
gepub-0.6.9.0 lib/gepub/sorted_array.rb
gepub-0.6.8.9 lib/gepub/sorted_array.rb
gepub-0.6.8.8 lib/gepub/sorted_array.rb
gepub-0.6.8.7 lib/gepub/sorted_array.rb
gepub-0.6.8.6 lib/gepub/sorted_array.rb