Sha256: efdf17d2672db0c90d77883aa85b1def78966a7515631584023e2b562072f581
Contents?: true
Size: 1.71 KB
Versions: 3
Compression:
Stored size: 1.71 KB
Contents
class Array def equality_uniq uniq_elements = [] self.each {|e| uniq_elements.push(e) unless uniq_elements.index(e)} uniq_elements end def delete_at_indices(indices = []) not_deleted = Array.new self.each_with_index {|e,i| not_deleted.push(e) if !indices.include?(i)} not_deleted end end class DefaultInitArray < Array def initialize(*args, &initblock) super(*args) @initblock = initblock end def [](index) super(index) || (self[index] = @initblock.call(index)) end end class ArrayOfArrays < DefaultInitArray @@create_array = proc{|i| Array.new} def initialize(*args) super(*args, &@@create_array) end end class ArrayOfHashes < DefaultInitArray @@create_hash = proc{|i| Hash.new} def initialize(*args) super(*args, &@@create_hash) end end # Hash which takes a block that is called to give a default value when a key # has the value nil in the hash. class DefaultInitHash < Hash def initialize(*args, &initblock) super(*args) @initblock = initblock end def [](key) #super(key) || (self[key] = @initblock.call(key)) fetch(key) { store(key, @initblock.call(key)) } end end unless Object.constants.include?("TimesClass") TimesClass = (RUBY_VERSION < "1.7") ? Time : Process end def time_and_puts(string, &block) if $TIME_AND_PUTS_VERBOSE print string; STDOUT.flush end starttime = [Time.new, TimesClass.times] block.call endtime = [Time.new, TimesClass.times] duration = endtime[0] - starttime[0] begin load = [((endtime[1].utime+endtime[1].stime)-(starttime[1].utime+starttime[1].stime))/duration*100.0, 100.0].min puts " (%.2f s %.2f%%)" % [duration, load] if $TIME_AND_PUTS_VERBOSE rescue FloatDomainError end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rpdf2txt-0.8.4 | lib/rpdf2txt-rockit/base_extensions.rb |
rpdf2txt-0.8.3 | lib/rpdf2txt-rockit/base_extensions.rb |
rpdf2txt-0.8.2 | lib/rpdf2txt-rockit/base_extensions.rb |