Class Config
In: lib/rs/config.rb
Parent: Object

Convenience class for managing configuration

Methods

default   load_rc   method_missing   new  

Public Class methods

Create/reset the default $config object

[Source]

# File lib/rs/config.rb, line 36
  def self.default()
    $config = new :prompt              => "rs> ", 
                  :continuation_prompt => "..> ",
                  :ruby_return         => true   
  end

Load the user‘s configuration file

[Source]

# File lib/rs/config.rb, line 43
  def self.load_rc(file = '~/.rs/rc')
    # Load user config
    load file
  
  rescue LoadError
    # No problem
  end

Create a config object

[Source]

# File lib/rs/config.rb, line 52
  def initialize(hash)
    @store = hash
  end

Public Instance methods

Emulate normal arbitrary accessors and the two suffixes, ! to mean to set the attribute to true, ? to query whether the attr can be considered true

[Source]

# File lib/rs/config.rb, line 60
  def method_missing(sym, *args, &block)
    a, suffix = sym.to_s[0...-1], sym.to_s[-1, 1]

    # Decide what to do
    case suffix
      when '='
        @store[a.intern] = *args

      when '?'
        !!@store[a.intern]

      when '!'
        @store[a.intern] = true

      else
        @store[sym]
    end                               # sym[-1]
  end

[Validate]