Class: NsOptions::Options
- Inherits:
-
Object
- Object
- NsOptions::Options
- Defined in:
- lib/ns-options/options.rb
Instance Method Summary collapse
-
#[](name) ⇒ Object
for hash with indifferent access behavior.
- #[]=(name, value) ⇒ Object
- #add(name, opt) ⇒ Object
- #each(*args, &block) ⇒ Object
- #empty?(*args, &block) ⇒ Boolean
- #get(name) ⇒ Object
-
#initialize ⇒ Options
constructor
A new instance of Options.
- #keys(*args, &block) ⇒ Object
- #required_set? ⇒ Boolean
- #rm(name) ⇒ Object
- #set(name, new_value) ⇒ Object
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
7 8 9 |
# File 'lib/ns-options/options.rb', line 7 def initialize @hash = Hash.new end |
Instance Method Details
#[](name) ⇒ Object
for hash with indifferent access behavior
12 |
# File 'lib/ns-options/options.rb', line 12 def [](name); @hash[name.to_s]; end |
#[]=(name, value) ⇒ Object
13 |
# File 'lib/ns-options/options.rb', line 13 def []=(name, value); @hash[name.to_s] = value; end |
#add(name, opt) ⇒ Object
19 20 21 |
# File 'lib/ns-options/options.rb', line 19 def add(name, opt) self[name] = opt end |
#each(*args, &block) ⇒ Object
16 |
# File 'lib/ns-options/options.rb', line 16 def each(*args, &block); @hash.each(*args, &block); end |
#empty?(*args, &block) ⇒ Boolean
17 |
# File 'lib/ns-options/options.rb', line 17 def empty?(*args, &block); @hash.empty?(*args, &block); end |
#get(name) ⇒ Object
27 28 29 |
# File 'lib/ns-options/options.rb', line 27 def get(name) (option = self[name]) ? option.value : nil end |
#keys(*args, &block) ⇒ Object
15 |
# File 'lib/ns-options/options.rb', line 15 def keys(*args, &block); @hash.keys(*args, &block); end |
#rm(name) ⇒ Object
23 24 25 |
# File 'lib/ns-options/options.rb', line 23 def rm(name) @hash.delete(name.to_s) end |
#set(name, new_value) ⇒ Object
31 32 33 |
# File 'lib/ns-options/options.rb', line 31 def set(name, new_value) self[name].value = new_value end |