Module: Ghaki::Bool::Options

Defined in:
lib/ghaki/bool/options.rb

Overview

Boolean attribute helpers.

Instance Method Summary collapse

Instance Method Details

#bool_option(opts, defval, token) ⇒ Object

Given token, check option hash and return value or default.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ghaki/bool/options.rb', line 8

def bool_option opts, defval, token
  newval = if opts.has_key?(token) and (not opts[token].nil?)
             opts[token]
           else
             defval
           end
  func_put = (token.to_s + '=').to_sym
  unless self.respond_to?(func_put)
    func_put = (token.to_s + '!').to_sym
    unless self.respond_to?(func_put)
      raise NoMethodError, 'Missing Asssignment',
        func_put, opts, defval, token
    end
  end
  send( func_put, newval )
end

#bool_options(opts, defval, *tokens) ⇒ Object

Handle multiple tokens for checking boolean options.



26
27
28
29
30
# File 'lib/ghaki/bool/options.rb', line 26

def bool_options opts, defval, *tokens
  tokens.each do |token|
    bool_option opts, defval, token
  end
end