Module: Gibbler::String
- Includes:
- Object
- Included in:
- Bignum, Date, FalseClass, Fixnum, Float, Regexp, String, Symbol, TrueClass, URI::Generic
- Defined in:
- lib/gibbler.rb
Overview
Creates a digest based on: CLASS:LENGTH:VALUE
. This method can be used for any class where the to_s
method returns an appropriate unique value for this instance. It’s used by default for Symbol, Class, Fixnum, and Bignum. e.g.
"str" => String:3:str => 509a839ca1744c72e37759e7684ff0daa3b61427
:sym => Symbol:3:sym => f3b7b3ca9529002c6826b1ef609d3583c356c8c8
To use use method in other classes simply:
class MyStringLikeClass
include Gibbler::String
end
Class Method Summary collapse
Instance Method Summary collapse
-
#__gibbler(h = self) ⇒ Object
Creates a digest for the current state of self.
Methods included from Object
#digest_cache, #freeze, #gibbled?, #gibbler, #gibbler_debug, #gibbler_fields, gibbler_fields
Class Method Details
.included(obj) ⇒ Object
318 319 320 321 |
# File 'lib/gibbler.rb', line 318 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.
324 325 326 327 328 329 330 |
# File 'lib/gibbler.rb', line 324 def __gibbler(h=self) klass = h.class value = h.nil? ? "\0" : h.to_s a = Gibbler.digest "%s:%d:%s" % [klass, value.size, value] gibbler_debug klass, a, [klass, value.size, value] a end |