Class: YAMLParser
- Inherits:
-
Object
- Object
- YAMLParser
- Defined in:
- lib/yaml-parser.rb
Direct Known Subclasses
Constant Summary collapse
- @@hash =
{}
Class Method Summary collapse
-
.parse(filename) ⇒ Object
Implement a method parse the contents of a YAML file and return an object whose values are accessible using the [] operator or method calls.
Instance Method Summary collapse
Class Method Details
.parse(filename) ⇒ Object
Implement a method parse the contents of a YAML file and return an object whose values are accessible using the [] operator or method calls
Note: Use of the YAML library is fine (encouraged, even) but please don’t
use any third-party gems that enable the required functionality.
16 17 18 19 20 21 22 23 24 |
# File 'lib/yaml-parser.rb', line 16 def self.parse(filename) # Open and read the file, store it as a variable 'file' file = open(filename, &:read) # Convert the file variable into a hash so that we can use the [] operator @@hash = YAML.load(file) custom = SpecialObject.new(@@hash) end |
Instance Method Details
#hash ⇒ Object
7 8 9 |
# File 'lib/yaml-parser.rb', line 7 def hash @@hash end |