Top Level Namespace
Defined Under Namespace
Modules: Apigen
Instance Method Summary collapse
-
#attribute_setter_getter(attribute) ⇒ Object
Creates a setter/getter method for :attribute.
Instance Method Details
#attribute_setter_getter(attribute) ⇒ Object
Creates a setter/getter method for :attribute.
attribute_setter_getter :name
is equivalent to:
def name value = nil
if value.nil?
@name
else
@name = value
end
end
15 16 17 18 19 20 21 22 23 |
# File 'lib/apigen/util.rb', line 15 def attribute_setter_getter(attribute) define_method attribute.to_s.to_sym do |value = nil| if value.nil? instance_variable_get "@#{attribute}" else instance_variable_set "@#{attribute}", value end end end |