Class: YAML::Options
- Inherits:
-
Hash
- Object
- Hash
- YAML::Options
show all
- Defined in:
- lib/yaml/options.rb,
lib/yaml/options/version.rb
Constant Summary
collapse
- VERSION =
"1.0.1"
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(hash = {}) ⇒ Options
Returns a new instance of Options.
16
17
18
19
20
|
# File 'lib/yaml/options.rb', line 16
def initialize(hash = {})
hash.each do |key, value|
self[key] = convert(value)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/yaml/options.rb', line 30
def method_missing(name, *args)
name_string = name.to_s
if name_string.chomp!("=")
self[name_string] = args.first
else
self[name]
end
end
|
Class Method Details
.load(str) ⇒ Object
7
8
9
10
11
|
# File 'lib/yaml/options.rb', line 7
def self.load(str)
hash = YAML.load(str)
raise ArgumentError, "str must be a YAML hash" unless hash.is_a?(Hash)
new(hash)
end
|
Instance Method Details
#[](key) ⇒ Object
22
23
24
|
# File 'lib/yaml/options.rb', line 22
def [](key)
super(key.to_sym)
end
|
#[]=(key, value) ⇒ Object
26
27
28
|
# File 'lib/yaml/options.rb', line 26
def []=(key, value)
super(key.to_sym, value)
end
|
#respond_to_missing?(name, include_private) ⇒ Boolean
39
40
41
|
# File 'lib/yaml/options.rb', line 39
def respond_to_missing?(name, include_private)
true
end
|