Class: Mascot::DAT::Parameters
- Inherits:
-
Object
- Object
- Mascot::DAT::Parameters
- Includes:
- Enumerable
- Defined in:
- lib/mascot/dat/parameters.rb
Instance Attribute Summary collapse
-
#names ⇒ Object
readonly
An array of parameter names.
-
#parameters ⇒ Object
readonly
A hash to access the parameters by the parameter name.
Instance Method Summary collapse
- #[](k) ⇒ Object
-
#initialize(params_str) ⇒ Parameters
constructor
A new instance of Parameters.
- #method_missing(m, args) ⇒ Object
Constructor Details
#initialize(params_str) ⇒ Parameters
Returns a new instance of Parameters.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mascot/dat/parameters.rb', line 16 def initialize params_str @parameters = {} @names = [] params_str.split("\n").each do |l| k,v = l.split("=") next unless k && v @parameters[k] = v @names << k end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, args) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/mascot/dat/parameters.rb', line 32 def method_missing(m,args) if @parameters.has_key?(m.to_s) @parameters[m.to_s] else super end end |
Instance Attribute Details
#names ⇒ Object (readonly)
An array of parameter names
7 8 9 |
# File 'lib/mascot/dat/parameters.rb', line 7 def names @names end |
#parameters ⇒ Object (readonly)
A hash to access the parameters by the parameter name
14 15 16 |
# File 'lib/mascot/dat/parameters.rb', line 14 def parameters @parameters end |
Instance Method Details
#[](k) ⇒ Object
28 29 30 |
# File 'lib/mascot/dat/parameters.rb', line 28 def []k @parameters[k] end |