module AutoForme::OptsAttributes

  1. lib/autoforme/opts_attributes.rb

Methods

Public Instance

  1. opts_attribute

Public Instance methods

opts_attribute (*meths)

Setup methods for each given argument such that if the method is called with an argument or block, it sets the value of the related option to that argument or block. If called without an argument or block, it returns the stored option value.

[show source]
   # File lib/autoforme/opts_attributes.rb
 8 def opts_attribute(*meths)
 9   meths.each do |meth|
10     define_method(meth) do |*args, &block|
11       if block
12         if args.empty?
13           opts[meth] = block
14         else
15           raise ArgumentError, "No arguments allowed if passing a block"
16         end
17       end
18 
19       case args.length
20       when 0
21         opts[meth]
22       when 1
23         opts[meth] = args.first
24       else
25         raise ArgumentError, "Only 0-1 arguments allowed"
26       end
27     end
28   end
29 end