Module: StateFu::Applicable::InstanceMethods

Defined in:
lib/support/applicable.rb

Instance Method Summary collapse

Instance Method Details

#apply!(_options = nil, &block) ⇒ Object

if given a hash of options (or a splatted arglist containing one), merge them into @options. If given a block, eval it (yielding self if the block expects it)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/support/applicable.rb', line 9

def apply!( _options=nil, &block )
  if _options.is_a?(Array)
    _options  = _options.dup.extract_options!.symbolize_keys
  else          
    _options ||= {}
    _options = _options.symbolize_keys!
  end

  @options = @options.nil?? _options : @options.merge(_options)
  returning self do
    if block_given?
      case block.arity.abs
      when 1, -1
        instance_exec self, &block
      when 0
        instance_exec &block
      else
        raise ArgumentError, "Your block wants too many arguments!"
      end
    end
  end
end