40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/familysearch/gedcomx/super_coercion.rb', line 40
def []=(key, value)
if value && [Array,Hash].include?(value.class)
into = self.class.key_coercion(key) || self.class.value_coercion(value)
if value && into
if into.class == Array && value.class == Array
value = value.collect do |v|
if into[0].respond_to?(:coerce)
into[0].coerce(v)
else
into[0].new(v)
end
end
elsif into.class == Hash && value.class == Hash
into_value = into['key']
value = value.inject({}) do |h, (k, v)|
if into_value.respond_to?(:coerce)
h[k] = into_value.coerce(v)
else
h[k] = into_value.new(v)
end
h
end
else
if into.respond_to?(:coerce)
value = into.coerce(value)
else
value = into.new(value)
end
end
end
end
super(key, value)
end
|