Class: Unimatrix::Configuration

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/unimatrix/configuration.rb

Class Method Summary collapse

Class Method Details

.field(field_name, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/unimatrix/configuration.rb', line 13

def self.field( field_name, options={} )
  class_eval(
    "def #{ field_name }( *arguments ); " +
       "@#{ field_name } = arguments.first unless arguments.empty?; " +
       "@#{ field_name } || " +
         ( options[ :default ].nil? ?
            "nil" :
            ( options[ :default ].is_a?( String ) ?
                "'#{ options[ :default ] }'" :
                  "#{ options[ :default ] }" ) ) + ";" +
    "end",
    __FILE__,
    __LINE__
  )
end