Class: NsOptions::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/ns-options/options.rb

Instance Method Summary collapse

Constructor Details

#initializeOptions

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

Returns:



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

#required_set?Boolean

Returns:



35
36
37
# File 'lib/ns-options/options.rb', line 35

def required_set?
  are_all_these_options_set? required_options
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