Module: Rum::Docker::AttrCallable
Overview
Mixin to enable adding instance methods to a class that gets or sets-and-returns the given attr of the instance.
Instance Method Summary collapse
-
#attr_method_accessor(*args) ⇒ Object
Method to define a method-accessor for each argument supplied.
Instance Method Details
#attr_method_accessor(*args) ⇒ Object
Method to define a method-accessor for each argument supplied. When extended by a class
Example:
class Fizz
extend AttrCallable
attr_method_accessor :buzz
end
fizz = Fizz.new
fizz.buzz "foo"
fizz.buzz
# => "foo"
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rumrunner/docker.rb', line 30 def attr_method_accessor(*args) args.each do |var| define_method var do |value = nil| if value.nil? instance_variable_get :"@#{var}" else instance_variable_set :"@#{var}", value self end end end end |