Skip to content
Implementation-agnostic git-like hashes and history for Ruby objects
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Gibbler - v0.6 ALPHA

Git-like hashes and history for Ruby objects for Ruby 1.8, 1.9 and JRuby.

NOTE: Digests changed in the 0.6 release for Class, Module, and Proc objects. See “News” below for more info.

Example 1 – Basic Usage

require 'gibbler'

"kimmy".gibbler              # => c8027100ecc54945ab15ddac529230e38b1ba6a1
:kimmy.gibbler               # => 52be7494a602d85ff5d8a8ab4ffe7f1b171587df

config = {}
config.gibbler               # => 4fdcadc66a38feb9c57faf3c5a18d5e76a6d29bf
config.gibbled?              # => false

config[:server] = {          
  :users => [:dave, :ali],   
  :ports => [22, 80, 443]    
config.gibbled?              # => true
config.gibbler               # => ef23d605f8c4fc80a8e580f9a0e8dab8426454a8 

config[:server][:users] << :yanni

config.gibbler               # => 4c558a56bc2abf5f8a845a69e47ceb5e0003683f

config.gibbler.short         # => 4c558a56

Example 2 – Object History

Gibbler can also keep track of the history of changes to an object. By default Gibbler supports history for Hash, Array, and String objects. The gibbler_commit method creates a clone of the current object and stores in an instance variable using the current hash digest as the key.

require 'gibbler'
require 'gibbler/history'

a = { :magic => :original }     
a.gibbler_commit             # => d7049916ddb25e6cc438b1028fb957e5139f9910

a[:magic] = :updated           
a.gibbler_commit             # => b668098e16d08898532bf3aa33ce2253a3a4150e

a[:magic] = :changed 
a.gibbler_commit             # => 0b11c377fccd44554a601e5d2b135c46dc1c4cb1

a.gibbler_history            # => d7049916, b668098e, 0b11c377

a.gibbler_revert! 'd7049916' # Return to a specific commit
a.gibbler                    # => d7049916ddb25e6cc438b1028fb957e5139f9910
a                            # => { :magic => :original } 

a.delete :magic

a.gibbler_revert!            # Return to the previous commit  
a.gibbler                    # => 0b11c377fccd44554a601e5d2b135c46dc1c4cb1
a                            # => { :magic => :changed }

a.gibbler_object 'b668098e'  # => { :magic => :updated }
a.gibbler_stamp              # => 2009-07-01 18:56:52 -0400

Example 3 – Method Aliases

If you have control over the namespaces of your objects, you can use the method aliases to tighten up your code a bit. The “gibbler” and “gibbled?” methods can be accessed via “digest” and “changed?”, respectively. (The reason they're not enabled by default is to avoid conflicts.)

require 'gibbler'
require 'gibbler/aliases'

"kimmy".digest               # => c8027100ecc54945ab15ddac529230e38b1ba6a1
:kimmy.digest                # => 52be7494a602d85ff5d8a8ab4ffe7f1b171587df

a = [:a, :b, :c]
a.digest                     # => e554061823b8f06367555d1ee4c25b4ffee61944
a << :d
a.changed?                   # => true

The history methods also have aliases which remove the “gibbler_”.

require 'gibbler'
require 'gibbler/history'
require 'gibbler/aliases'

a = { :magic => :original }     
# etc...

Supported Classes

Gibbler methods are available only to the classes which explicitly include them (see RDocs for details on which classes are supported by default). You can also extend custom objects:

class FullHouse
  include Gibbler::Complex
  attr_accessor :roles

a =
a.gibbler                    # => 4192d4cb59975813f117a51dcd4454ac16df6703

a.roles = [:jesse, :joey, :danny, :kimmy, :michelle, :dj, :stephanie]
a.gibbler                    # => 6ea546919dc4caa2bab69799b71d48810a1b48fa

Gibbler::Complex creates a digest based on the name of the class and the names and values of the instance variables. See the RDocs for other Gibbler::* types.

If you want to support all Ruby objects, add the following to your application:

class Object
  include Gibbler::String

Gibbler::String creates a digest based on the name of the class and the output of the to_s method. This is a reasonable default for most objects however any object that includes the object address in to_s (e.g. “Object:0x0x4ac9f0…”) will produce unreliable digests (because the address can change).

ALPHA Notice

This code is hella fresh (est 2009-06-25). It's barely tested and the interface may change, but it's fun to play with. I'll happily accept patches. Some things to keep in mind:

  • Gibbler history is not suitable for very large objects since it keeps complete copies of the object in memory. This is a very early implementation of this feature so don't rely on it for production code.

  • Digest calculation may change between non-trivial releases.

  • There has been very little testing for concurrency issues. (Anyone interested?)


2009-07-20: Digest change for instances of Class, Module, and Proc

Digest calculation has changed for Class, Module, and Proc objects. Digests created with Gibbler 0.5.x and earlier will not match the ones created by 0.6.

  • Class and Module objects were calculating digests based on the output of self.to_s. This was a problem because that string contains a memory address which can change arbitrarily. The new calculation is based on the object class, the length of name, and the name itself. e.g. "Class:6:Object" # => '5620e4a8b10ec6830fece61d33f5d3e9a349b4c2'

  • Proc objects were including the return value of self.binding in the digest calculation. This is not reliable because the binding includes an arbitrary address. The new calculation is based on the class name, the arity, and whether it was created with a lambda.

Also note that this change affects the digests for Hashes and Arrays that contain instances of Class, Module, or Proc.

2009-07-17: Improved support for Symbol and Fixnum

With the upgrade to Attic 0.4, the gibbled? method and object history is now available for Symbol and Fixnum objects.

Known Issues

  • gibbler or gibbled? must be called at least once before gibbled? will be able to return a useful value (otherwise there is no previous digest value to compare to)

  • Digests for Bignum objects are different between (MRI) Ruby and JRuby. Does anyone know why?

  • Digests for Proc objects are different between Ruby 1.8 and 1.9 because Proc.arity returns different values and 1.8 has no lambda? method.


Via Rubygems, one of:

$ gem install gibbler
$ gem install delano-gibbler

or via download:

What People Are Saying

  • “nice approach - everything is an object, every object is 'gittish'” – @olgen_morten

  • “gibbler is just awesome” – @TomK32

  • “wie cool ist Gibbler eigentlich?” – @we5

  • “it's nice idea and implementation!” – HristoHristov

More Info


  • Kalin Harvey (krrh) for the early feedback and artistic direction.


  • Delano (


See: LICENSE.txt

Something went wrong with that request. Please try again.