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
# File 'lib/options.rb', line 28

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

#opt_if(sym, *types) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/options.rb', line 44

def opt_if(sym, *types)
  v = @options[sym]
  r = if v
    if types.empty?
      :ok
    elsif types.find {|t| v.is_a? t}
      :ok
    end
  elsif types.include? NilClass
    :ok
  end
  if r == :ok
    if block_given?
      yield v
    else
      v
    end
  end
end