Module: ChefWorkflow::AttrSupport
- Included in:
- EC2Support, GeneralSupport, IPSupport, KnifeSupport, Scheduler, VagrantSupport
- Defined in:
- lib/chef-workflow/support/attr.rb
Overview
Mixin to make exposing attr modification via ‘instance_eval` easier.
Instance Method Summary collapse
-
#fancy_attr(name) ⇒ Object
Defines an attribute that is both a standard writer, but with an overloaded reader that accepts an optional argument.
Instance Method Details
#fancy_attr(name) ⇒ Object
Defines an attribute that is both a standard writer, but with an overloaded reader that accepts an optional argument. Equivalent to this code for ‘foo`:
attr_writer :foo
def foo(*args)
if args.count > 0
@foo = arg
end
@foo
end
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/chef-workflow/support/attr.rb', line 20 def fancy_attr(name) class_eval <<-EOF attr_writer :#{name} def #{name}(*args) if args.count > 0 @#{name} = args.first end @#{name} end EOF end |