Module: Hbc::CLI::Options::ClassMethods

Defined in:
Library/Homebrew/cask/lib/hbc/cli/options.rb

Instance Method Summary collapse

Instance Method Details

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'Library/Homebrew/cask/lib/hbc/cli/options.rb', line 15

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



9
10
11
12
13
# File 'Library/Homebrew/cask/lib/hbc/cli/options.rb', line 9

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