Class: LoadFile::Loader
- Inherits:
-
Hash
- Object
- Hash
- LoadFile::Loader
- Defined in:
- lib/load_file/loader.rb
Overview
A class to load ‘file` into Hash, find or create constant by `constant_name`.
Instance Method Summary collapse
-
#initialize(file, constant_name, namespace: Object) ⇒ Loader
constructor
A new instance of Loader.
-
#set_constant ⇒ Object
Set ‘values` into `constant` if not exists.
-
#set_constant! ⇒ Object
Override ‘values` into `constant`.
Constructor Details
#initialize(file, constant_name, namespace: Object) ⇒ Loader
Returns a new instance of Loader.
9 10 11 12 13 14 15 |
# File 'lib/load_file/loader.rb', line 9 def initialize(file, constant_name, namespace: Object) @file = file @namespace = namespace @constant = find_or_define(constant_name) update parsed_content end |
Instance Method Details
#set_constant ⇒ Object
Set ‘values` into `constant` if not exists.
18 19 20 |
# File 'lib/load_file/loader.rb', line 18 def set_constant each { |key, value| constant[key] ||= value } end |
#set_constant! ⇒ Object
Override ‘values` into `constant`.
23 24 25 |
# File 'lib/load_file/loader.rb', line 23 def set_constant! each { |key, value| constant[key] = value } end |