lib/config.rb
# define convinence methods for each of the configuration paramaters special
# methods added for parameters that take booleans, e.g. dont_xxxx or xxxx!
define convinence methods for each of the configuration paramaters special
methods added for parameters that take booleans, e.g.
define convinence methods for each of the configuration paramaters special methods added for parameters that take booleans e . g .
def methods_for(config, rcvr, prefix)
        config.reject { |k, _| PRIVATE.include?(k) }.map do |k, v|
          (case v
           when true, false
             [[:"dont_#{k}", -> { @config[k] = false }],
              [:"do_#{k}",   -> { @config[k] = true }],
              [:"#{k}!",     -> { @config[k] = true }],
              [:"#{k}?",     -> { @config[k] }],
              [:"#{k}=",     lambda { |l|
                unless [TrueClass, FalseClass].include?(l.class)
                  raise TypeError, "expected #{l.inspect} to be a kind_of? Bool (true, or false)"
                end
                @config[k] = l
              }]]
           else
             [[:"#{k}=",     lambda { |l|
                               unless l.is_a?(v.class)
                                 raise TypeError, "expected #{l.inspect} to be a kind_of? #{v.class}"
                               end
                               @config[k] = l
                             }]]
          end +
            [[:"#{k}", -> { @config[k] }]]
          ).map do |meth, body|
            rcvr.define_singleton_method(:"#{prefix}#{meth}", &body)
          end
        end.flatten
      end
def methods_for ( config , rcvr , prefix ) config . reject { | k , _ | PRIVATE . include? ( k ) } . map do | k , v | ( case v when true , false [ [ :" dont_ #{ k } " , -> { @config [ k ] = false } ] , [ :" do_ #{ k } " , -> { @config [ k ] = true } ] , [ :" #{ k } ! " , -> { @config [ k ] = true } ] , [ :" #{ k } ? " , -> { @config [ k ] } ] , [ :" #{ k } = " , lambda { | l | unless [ TrueClass , FalseClass ] . include? ( l . class ) raise TypeError , "expected #{l.inspect} to be a kind_of? Bool (true, or false)" end @config [ k ] = l } ] ] else [ [ :" #{ k } = " , lambda { | l | unless l . is_a? ( v . class ) raise TypeError , "expected #{l.inspect} to be a kind_of? #{v.class}" end @config [ k ] = l } ] ] end + [ [ :" #{ k } " , -> { @config [ k ] } ] ] ) . map do | meth , body | rcvr . define_singleton_method ( :" #{ prefix } #{ meth } " , & body ) end end . flatten end
define convinence methods for each of the configuration paramaters special
methods added for parameters that take booleans, e.g.
define convinence methods for each of the configuration paramaters special methods added for parameters that take booleans e . g .
config
rcvr
prefix