8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/typecaster.rb', line 8
def attribute(name, options={})
attribute_name = name.to_sym
raw_attributes[attribute_name] = options
attributes[attribute_name] = nil
define_method(name) do
if instance_variable_defined?("@#{name}")
instance_variable_get("@#{name}")
elsif raw_attributes[attribute_name].has_key?(:default)
define_instance_variable(name, raw_attributes[attribute_name][:default])
else
define_instance_variable(name, nil)
end
end
define_method("#{name}=") do |val|
define_instance_variable(name, val)
end
end
|