44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/adv_accessor/dsl.rb', line 44
def adv_accessor(name,&b)
@adv_accessor ||= Hash.new { |h,k| h[k] = AdvAccessor::Base.new(:method => name) }
base = @adv_accessor[name]
dsl = AdvAccessor::DSL::Create.new(:base => base)
complex_block = lambda do
block = b
if b.arity == 0
block = lambda { |a| a.null_value = b }
end
block
end
create_writer = lambda do
define_method("#{name}=") do |arg|
base.value = arg
end
end
create_simple = lambda do
define_method(name) do
base.value
end
create_writer[]
end
create_complex = lambda do
define_method(name) do
AdvAccessor::DSL::Access.new(:base => base)
end
create_writer[]
end
if block_given?
complex_block[][dsl]
if dsl.complex
create_complex[]
else
create_simple[]
end
end
end
|