10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/sbuilder/extend.rb', line 10
def attr_accessor_with_default name, *default, &block
if( default.size != 1)
raise "Must either provide a default value or a default code block"
end
if ! default[0].respond_to?( :call )
define_method name.to_sym do
instance_variable_set("@#{name}", default[0]) unless instance_variable_defined?("@#{name}")
instance_variable_get("@#{name}")
end
else
define_method name.to_sym do
instance_variable_set("@#{name}", default[0] ) unless instance_variable_defined?("@#{name}")
instance_variable_get("@#{name}")
end
end
define_method "#{name}=".to_sym do |value|
instance_variable_set("@#{name}",value)
end
end
|