Module: Gibbler::String
- Includes:
- Object
- Included in:
- Addressable::URI, Bignum, Date, FalseClass, Fixnum, Float, MatchData, 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(digest_type = nil) ⇒ 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
403 404 405 406 |
# File 'lib/gibbler.rb', line 403 def self.included(obj) obj.extend Attic obj.attic :gibbler_cache end |
Instance Method Details
#__gibbler(digest_type = nil) ⇒ Object
Creates a digest for the current state of self.
409 410 411 412 413 414 415 |
# File 'lib/gibbler.rb', line 409 def __gibbler(digest_type=nil) klass = self.class value = self.nil? ? "\0" : self.to_s a = Gibbler.digest "%s:%d:%s" % [klass, value.size, value], digest_type gibbler_debug klass, a, [klass, value.size, value] a end |