Module: Gibbler::Array

Includes:
Object
Included in:
Array
Defined in:
lib/gibbler.rb

Overview

Creates a digest based on:

  • parse each element into an Array of digests like: CLASS:INDEX:VALUE.__gibbler

    • The gibbler method is called on each element so if it is a Hash or Array etc it will be parsed recursively according to the gibbler method for that class type.

  • Digest the Array of digests

  • Return the digest for class:length:value where:

    • “class” is equal to the current object class (e.g. Array).

    • “length” is the size of the Array of digests (which should equal the number of elements in the original Array object).

    • “value” is the Array of digests joined with a colon (“:”).

This method can be used by any class with an each method.

class MyNamedArray 
  include Gibbler::Array
end

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Object

#digest_cache, #freeze, #gibbled?, #gibbler, #gibbler_debug, #gibbler_fields, gibbler_fields

Class Method Details

.included(obj) ⇒ Object



393
394
395
396
# File 'lib/gibbler.rb', line 393

def self.included(obj)
  obj.extend Attic
  obj.attic :gibbler_cache
end

Instance Method Details

#__gibbler(h = self) ⇒ Object

Creates a digest for the current state of self.



399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/gibbler.rb', line 399

def __gibbler(h=self)
  klass = h.class
  d, index = [], 0
  h.each do |value| 
    d << '%s:%s:%s' % [value.class, index, value.__gibbler]
    index += 1
  end
  d = d.join(':').__gibbler
  a = Gibbler.digest '%s:%s:%s' % [klass, d.size, d]
  gibbler_debug klass, a, [klass, d.size, d]
  a
end