Class HArray
In: lib/facet/harray.rb
Parent: Hash

Description

HArray is an implemenation of the Array class using only Hashes. Regular Arrays are never used except once to delegate the pack method, and for *args parameters (since there is no way around those is some cases). HArray is for all practical purposes 100% compatible with Array.

HArray is slower then the built in Array class, but not as slow as one might expect, since a Hash in general is faster than an Array. It might be interesting to see how this would perform if it were written in c. Not all that useful, but an interesting example.

AUTHOR(s)

  • Thamas Sawyer

Methods

&   *   +   -   <<   <=>   ===   []   []   []=   assoc   at   collect   collect!   compact   compact!   concat   count   delete   delete_at   delete_if   each   each_index   eql?   fill   first   flatten   flatten!   include?   join   last   map!   new   new_h   nitems   pack   pop   push   qsort   rassoc   reindex   reindex!   reject!   reverse   reverse!   reverse_each   rindex   shift   slice   slice!   sort   sort!   to_a   to_ary   to_h   to_s   uniq   uniq!   unshift   values_at   |  

Constants

VERSION = '0.9.0'

External Aliases

[] -> get
[]= -> set
delete -> qdelete
delete_if -> qdelete_if

Public Class methods

Public Instance methods

empty? okay as is

index okay

map!()

Alias for collect!

def replace(ha)

  if ha.length < self.length
    (ha.length..self.length-1).each { |i| self.delete(i) }
    (0..ha.length-1).each { |i| self.set(i,ha[i]) }
  end

end

size okay

[Validate]