2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/RubyExt/OpenConstructor.rb', line 2
def set values, list = nil
unless list
if values.is_a? Hash
values.each do |k, v|
self.respond_to k.to_writer, v
end
else
values.instance_variables.each do |name|
accessor = name[1..name.size].to_writer
if self.respond_to? accessor
self.send accessor, values.instance_variable_get(name)
end
end
end
else
if values.is_a? Hash
values.each do |k, v|
self.respond_to k.to_writer, v if list.include? k
end
else
values.instance_variables.each do |name|
accessor = name[1..name.size]
if list.include?(accessor.to_sym)
accessor = accessor.to_writer
if self.respond_to?(accessor)
self.send accessor, values.instance_variable_get(name)
end
end
end
end
end
return self
end
|