Module: Doodle::ToHash

Included in:
BaseMethods
Defined in:
lib/doodle/to_hash.rb

Instance Method Summary collapse

Instance Method Details

#to_hashObject

create ‘pure’ hash of scalars only from attributes - hacky but works (kinda)



5
6
7
8
9
10
11
12
# File 'lib/doodle/to_hash.rb', line 5

def to_hash
  Doodle::Utils.symbolize_keys!(YAML::load(to_yaml.gsub(/!ruby\/object:.*$/, '')) || { }, true)
  #begin
  #  YAML::load(to_yaml.gsub(/!ruby\/object:.*$/, '')) || { }
  #rescue Object => e
  #  doodle.attributes.inject({}) {|hash, (name, attribute)| hash[name] = send(name); hash}
  #end
end

#to_string_hashObject

begin

YAML::load(to_yaml.gsub(/!ruby\/object:.*$/, '')) || { }

rescue Object => e

doodle.attributes.inject({}) {|hash, (name, attribute)| hash[name] = send(name); hash}

end



13
14
15
# File 'lib/doodle/to_hash.rb', line 13

def to_string_hash
  Doodle::Utils.stringify_keys!(YAML::load(to_yaml.gsub(/!ruby\/object:.*$/, '')) || { }, true)
end