6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/controll/helper/hash_access.rb', line 6
def hash_access_methods *args
options = args.
hash_name = options[:hash]
names = args
raise ArgumentError, "Must take a :hash option indicating the hash name to access" unless hash_name
raise ArgumentError, "Must take one or more names of methods to create" if names.blank?
names.each do |name|
define_method name do
unless instance_variable_get("@#{name}")
instance_variable_set "@#{name}", (send(hash_name)[name.to_sym]) || options[:default]
end
end
end
end
|