==(other)
click to toggle source
def ==(other)
@table == other.instance_variable_get(:@table)
end
[](meth)
click to toggle source
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
def []=(meth, value)
@table[meth.to_sym] = value
end
__explicit__()
click to toggle source
def __explicit__
@table
end
__hash__()
click to toggle source
def __hash__
@defaults.merge(@table)
end
__replace__(options)
click to toggle source
def __replace__(options)
@table = __to_hash__(options)
end
__to_hash__(obj)
click to toggle source
def __to_hash__(obj)
Options === obj ? obj.__hash__ : obj
end
default(defaults = {})
click to toggle source
def default defaults = {}
@defaults.merge!(__to_hash__(defaults))
end
method_missing(meth, *args, &block)
click to toggle source
Calls superclass method
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
def respond_to?(meth)
super || meth.to_s =~ /^\w+(=)?$/
end
respond_to_missing?(meth, private_method = false)
click to toggle source
def respond_to_missing?(meth, private_method = false)
meth.to_s =~ /^\w+(=)?$/
end