Module: Gibbler::Range

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

Overview

Creates a digest based on: CLASS:LENGTH:VALUE where LENGTH is the number of elements in the range and VALUE is the string representation of the range. e.g.

(1..100)   =>  Range:100:1..100  =>  d73ae2a7
(1...100)  =>  Range:99:1...100  =>  46c8a7d0

To use use method in other classes simply:

class ClassLikeRange 
  include Gibbler::Range
end

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Object

#gibbled?, #gibbler, #gibbler_debug

Class Method Details

.included(obj) ⇒ Object



342
343
344
345
# File 'lib/gibbler.rb', line 342

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.



348
349
350
351
352
353
354
355
# File 'lib/gibbler.rb', line 348

def __gibbler(h=self)
  klass = h.class
  value = h.nil? ? "\0" : h.to_s
  size = h.nil? ? 0 : h.to_a.size
  a = Gibbler.digest "%s:%d:%s" % [klass, size, value]
  gibbler_debug klass, a, [klass, size, value]
  a
end