10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/to_hash.rb', line 10
def self.eval_attributes(object, attributes)
result = {}
attributes = attributes.first if attributes.first.kind_of?(Hash)
case attributes
when Array
attributes.each do |attribute|
if attribute.kind_of?(Array)
result[attribute.first] = eval_object(object.send(attribute.first), attribute[1..-1])
else
result[attribute] = object.send(attribute)
end
end
when Hash
attributes.each do |key, attribute|
if attribute.kind_of?(Array)
result[key] = eval_object(object.send(attribute.first), attribute[1..-1])
else
result[key] = object.send(attribute)
end
end
end
result
end
|