class OptParseBuilder::ArgumentValues
Like OpenStruct, in that it allows access as through either a Hash or a Struct, but raises an error if you try to read a value that has not been set.
Strings and symbols may be interchanged freely for hash access.
A value may only by set using hash syntax:
arg_values = ArgumentValues.new arg_values[:one] = 1 arg_values["two"] = 2
But may be retrieved using hash syntax:
arg_values["one"] # => 1 arg_values[:two] # => 2
or struct syntax:
arg_values.one # => 1 arg_values.two # => 2
Public Class Methods
new()
click to toggle source
Create an empty instance.
# File lib/opt_parse_builder/argument_values.rb, line 27 def initialize @h = {} end
Public Instance Methods
[](key)
click to toggle source
Get a value. The key may be either a string or a symbol. Raises KeyError if the collection does not have that key.
# File lib/opt_parse_builder/argument_values.rb, line 50 def [](key) @h.fetch(key.to_sym) end
[]=(key, value)
click to toggle source
Set a key to a value. The key may be either a string or a symbol.
# File lib/opt_parse_builder/argument_values.rb, line 44 def []=(key, value) @h[key.to_sym] = value end
empty?()
click to toggle source
Return true if the collection is empty.
# File lib/opt_parse_builder/argument_values.rb, line 32 def empty? @h.empty? end
has_key?(key)
click to toggle source
Return true if the collection contains the key, which may be either a symbol or a string.
# File lib/opt_parse_builder/argument_values.rb, line 38 def has_key?(key) @h.has_key?(key.to_sym) end