Module: CKick::Hashable

Included in:
Dependencies, Project, SubDirectory, Target
Defined in:
lib/ckick/hashable.rb

Overview

mixin enabling hash serialization

Instance Method Summary collapse

Instance Method Details

#to_hashObject

transforms object to Hash such that { :instance_variable => value }



14
15
16
17
18
19
20
# File 'lib/ckick/hashable.rb', line 14

def to_hash
  a = {}
  instance_variables_as_key_values.each do |name, obj|
    a[name] = object_value(obj)
  end
  a
end

#to_no_empty_value_hashObject

transforms object to Hash such that { :instance_variable => value }, excluding any pair where value responds true to :empty? method



23
24
25
26
27
28
29
30
31
# File 'lib/ckick/hashable.rb', line 23

def to_no_empty_value_hash
  a = {}
  instance_variables_as_key_values.each do |name, obj|
    if !obj.respond_to?(:empty?) || (obj.respond_to?(:empty?) && !obj.empty?)
      a[name] = object_value(obj)
    end
  end
  a
end