Method: Furnish::Provisioner::API#hash
- Defined in:
- lib/furnish/provisioners/api.rb
#hash ⇒ Object
Computes something suitable for storing in hash tables, also used for equality (see #==).
Accomplishes this by collecting all instance variables in an array, converting strings to a common encoding if necessary. Then, appends the class and Marshals the contents of the array.
432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/furnish/provisioners/api.rb', line 432 def hash Marshal.dump( instance_variables.sort.map do |x| y = instance_variable_get(x) y.kind_of?(String) ? y.encode("UTF-8", :invalid => :replace, :replace => "?".chr) : y end + [self.class] ).bytes.inject(0) { |x,y| x += y.ord } end |