class Commander::Command::Options

Public Class Methods

new(init=nil) click to toggle source
# File lib/rhc/commands.rb, line 69
def initialize(init=nil)
  @table = {}
  default(init) if init
end

Public Instance Methods

==(other) click to toggle source
# File lib/rhc/commands.rb, line 93
def ==(other)
  __hash__ == other.__hash__
end
[](meth) click to toggle source
# File lib/rhc/commands.rb, line 99
def [](meth)
  value = @table[meth.to_sym]
  value = value.call if value.is_a? Proc
  value
end
[]=(meth, value) click to toggle source
# File lib/rhc/commands.rb, line 96
def []=(meth, value)
  @table[meth.to_sym] = value
end
__hash__() click to toggle source
# File lib/rhc/commands.rb, line 110
def __hash__
  @table
end
__replace__(options) click to toggle source
# File lib/rhc/commands.rb, line 107
def __replace__(options)
  @table = __to_hash__(options).dup
end
__to_hash__(obj) click to toggle source
# File lib/rhc/commands.rb, line 113
def __to_hash__(obj)
  Options === obj ? obj.__hash__ : obj
end
default(defaults = {}) click to toggle source
# File lib/rhc/commands.rb, line 104
def default defaults = {}
  @table = @table.reverse_merge!(__to_hash__(defaults))
end
method_missing(meth, *args, &block) click to toggle source
# File lib/rhc/commands.rb, line 76
def method_missing meth, *args, &block
  if meth.to_s =~ %r^\w+=$/
    raise ArgumentError, "Options does not support #{meth} without a single argument" if args.length != 1
    self[meth.to_s.chop] = args.first
  elsif meth.to_s =~ %r^\w+$/
    if !@table.has_key?(meth)
      begin; return super; rescue NoMethodError; nil; end
    end
    raise ArgumentError, "Options does not support #{meth} with arguments" if args.length != 0
    self[meth]
  else
    super
  end
end
respond_to?(meth) click to toggle source
# File lib/rhc/commands.rb, line 73
def respond_to?(meth)
  super || meth.to_s =~ %r^\w+(=)?$/
end
respond_to_missing?(meth, private_method = false) click to toggle source
# File lib/rhc/commands.rb, line 90
def respond_to_missing?(meth, private_method = false)
  meth.to_s =~ %r^\w+(=)?$/
end