Module: Options

Included in:
Renamer
Defined in:
lib/options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



26
27
28
# File 'lib/options.rb', line 26

def options
  @options
end

Instance Method Details

#opt(sym, *types) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/options.rb', line 28

def opt(sym, *types)
  v = @options[sym]
  if v
    unless types.empty?
      if types.find {|t| v.is_a? t}
        if block_given?
          yield v
        else
          v
        end
      else
        raise BadOptionValueError.new(sym, v.class, types)
      end
    else
      if block_given?
        yield v
      else
        v
      end
    end
  elsif !types.include? NilClass
    raise MissingOptionError.new(sym)
  end
end

#opt_if(sym, *types) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/options.rb', line 53

def opt_if(sym, *types)
  begin
    v = opt sym, *types
  rescue OptionError
  end
  if block_given?
    yield v if v
  else
    v
  end
end