Module: Doodle::ToHash
- Included in:
- BaseMethods
- Defined in:
- lib/doodle/to_hash.rb
Instance Method Summary collapse
-
#to_hash ⇒ Object
create ‘pure’ hash of scalars only from attributes - hacky but works (kinda).
-
#to_string_hash ⇒ Object
begin YAML::load(to_yaml.gsub(/!ruby/object:.*$/, ”)) || { } rescue Object => e doodle.attributes.inject({}) {|hash, (name, attribute)| hash = send(name); hash} end.
Instance Method Details
#to_hash ⇒ Object
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_hash ⇒ Object
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 |