80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/confinement.rb', line 80
def builder_getter(method_name, klass, ivar, new: [])
init_parameters = [*new, "&block"].join(", ")
class_eval(<<~RUBY, __FILE__, __LINE__)
def #{method_name}(&block)
if #{ivar}
if block_given?
raise "#{method_name} is already set up"
end
return #{ivar}
end
if !block_given?
raise "Can't initialize #{method_name} without block"
end
#{ivar} = #{klass}.new(#{init_parameters})
#{ivar}
end
RUBY
end
|