Method: Map::Options.for

Defined in:
lib/ima/options.rb

.for(arg) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ima/options.rb', line 5

def for(arg)
  options =
    case arg
      when Hash
        arg
      when Array
        parse(arg)
      when String, Symbol
        {arg => true}
      else
        raise(ArgumentError, arg.inspect) unless arg.respond_to?(:to_hash)
        arg.to_hash
    end

  unless options.is_a?(Options)
    options = Map.for(options)
    options.extend(Options)
  end

  raise unless options.is_a?(Map)

  options
end