Class: Opt::Command::Result

Inherits:
Hash
  • Object
show all
Defined in:
lib/opt/command.rb

Overview

A hash-like result object.

Allow for method-access to all key-value pairs similar to ‘OpenStruct`.

Examples:

result = opt.parse %w(--help --level=5 add --exec bash sh)
result.help? #=> true
result.level #=> "5"
result.command #=> ["add"]
result.exec #=> ["bash", "sh"]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResult

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Result.



229
230
231
232
# File 'lib/opt/command.rb', line 229

def initialize
  @command = []
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mth, *args, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



246
247
248
249
250
251
252
# File 'lib/opt/command.rb', line 246

def method_missing(mth, *args, &block)
  if mth =~ /^(\w+)\??$/ && key?($1) && args.empty? && block.nil?
    fetch $1
  else
    super
  end
end

Instance Attribute Details

#commandArray<String> (readonly)

A list of command names.

Returns:

  • (Array<String>)

    List of commands.



225
226
227
# File 'lib/opt/command.rb', line 225

def command
  @command
end

Instance Method Details

#respond_to_missing?(mth) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


236
237
238
239
240
241
242
# File 'lib/opt/command.rb', line 236

def respond_to_missing?(mth)
  if mth =~ /^(\w)\??$/ && key?($1)
    true
  else
    super
  end
end