class Commander::Command::Options
Public Class Methods
new(init=nil)
click to toggle source
# File lib/rhc/commands.rb, line 127 def initialize(init=nil) @defaults = {} @table = {} default(init) if init end
Public Instance Methods
==(other)
click to toggle source
# File lib/rhc/commands.rb, line 164 def ==(other) @table == other.instance_variable_get(:@table) end
[](meth)
click to toggle source
# File lib/rhc/commands.rb, line 155 def [](meth) k = meth.to_sym value = @table.has_key?(k) ? @table[k] : @defaults[k] value = value.call if value.is_a? Proc value end
[]=(meth, value)
click to toggle source
# File lib/rhc/commands.rb, line 152 def []=(meth, value) @table[meth.to_sym] = value end
__explicit__()
click to toggle source
# File lib/rhc/commands.rb, line 161 def __explicit__ @table end
__hash__()
click to toggle source
# File lib/rhc/commands.rb, line 173 def __hash__ @defaults.merge(@table) end
__replace__(options)
click to toggle source
# File lib/rhc/commands.rb, line 170 def __replace__(options) @table = __to_hash__(options) end
__to_hash__(obj)
click to toggle source
# File lib/rhc/commands.rb, line 176 def __to_hash__(obj) Options === obj ? obj.__hash__ : obj end
default(defaults = {})
click to toggle source
# File lib/rhc/commands.rb, line 167 def default defaults = {} @defaults.merge!(__to_hash__(defaults)) end
method_missing(meth, *args, &block)
click to toggle source
Calls superclass method
# File lib/rhc/commands.rb, line 135 def method_missing meth, *args, &block if meth.to_s =~ /^\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 =~ /^\w+$/ if !@table.has_key?(meth) && !@defaults.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
Calls superclass method
# File lib/rhc/commands.rb, line 132 def respond_to?(meth) super || meth.to_s =~ /^\w+(=)?$/ end
respond_to_missing?(meth, private_method = false)
click to toggle source
# File lib/rhc/commands.rb, line 149 def respond_to_missing?(meth, private_method = false) meth.to_s =~ /^\w+(=)?$/ end