2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/chainy/module.rb', line 2
def chain_attr_accessor(symbol, *args)
if args.last.is_a?(Hash)
opts = args.pop
else
opts = {}
end
attr_accessor(symbol, *args)
prefix = opts[:prefix] || Chainy::Config.prefix
[].tap do |method_names|
method_names << symbol
method_names.concat args
end.each do |method_name|
new_method_name = "#{prefix}_#{method_name}"
define_method(new_method_name) do |*args|
send "#{method_name}=", *args
self
end
end
end
|