Module: Cask::Cmd::Options::ClassMethods

Defined in:
brew/Library/Homebrew/cask/cmd/options.rb

Instance Method Summary collapse

Instance Method Details

#option(name, method, default_value = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'brew/Library/Homebrew/cask/cmd/options.rb', line 18

def option(name, method, default_value = nil)
  @options ||= {}
  @options[name] = method

  return if method.respond_to?(:call)

  define_method(:"#{method}=") do |value|
    instance_variable_set(:"@#{method}", value)
  end

  if [true, false].include?(default_value)
    define_method(:"#{method}?") do
      return default_value unless instance_variable_defined?(:"@#{method}")

      instance_variable_get(:"@#{method}") == true
    end
  else
    define_method(:"#{method}") do
      return default_value unless instance_variable_defined?(:"@#{method}")

      instance_variable_get(:"@#{method}")
    end
  end
end

#optionsObject



11
12
13
14
15
16
# File 'brew/Library/Homebrew/cask/cmd/options.rb', line 11

def options
  @options ||= {}
  return @options unless superclass.respond_to?(:options)

  superclass.options.merge(@options)
end