vendor/bundle/ruby/2.6.0/gems/lumberjack-1.2.8/lib/lumberjack/formatter.rb
# Add a formatter for a class. The formatter can be specified as either an object
# that responds to the +call+ method or as a symbol representing one of the predefined
# formatters, or as a block to the method call.
#
# The predefined formatters are: :inspect, :string, :exception, and :pretty_print.
#
# You can add multiple classes at once by passing an array of classes.
#
# You can also pass class names as strings instead of the classes themselves. This can
# help avoid loading dependency issues. This applies only to classes; modules cannot be
# passed in as strings.
#
# === Examples
#
#   # Use a predefined formatter
#   formatter.add(MyClass, :pretty_print)
#
#   # Pass in a formatter object
#   formatter.add(MyClass, Lumberjack::Formatter::PrettyPrintFormatter.new)
#
#   # Use a block
#   formatter.add(MyClass){|obj| obj.humanize}
#
#   # Add statements can be chained together
#   formatter.add(MyClass, :pretty_print).add(YourClass){|obj| obj.humanize}
Add a formatter for a class. The formatter can be specified as either an object
that responds to the +call+ method or as a symbol representing one of the predefined
formatters, or as a block to the method call.



You can add multiple classes at once by passing an array of classes.

You can also pass class names as strings instead of the classes themselves. This can
help avoid loading dependency issues. This applies only to classes; modules cannot be
passed in as strings.

Examples








Add a formatter for a class . The formatter can be specified as either an object that responds to the + call + method or as a symbol representing one of the predefined formatters or as a block to the method call . You can add multiple classes at once by passing an array of classes . You can also pass class names as strings instead of the classes themselves . This can help avoid loading dependency issues . This applies only to classes ; modules cannot be passed in as strings . Examples
def add(klass, formatter = nil, &block)
      formatter ||= block
      if formatter.nil?
        remove(klass)
      else
        if formatter.is_a?(Symbol)
          formatter_class_name = "#{formatter.to_s.gsub(/(^|_)([a-z])/) { |m| $~[2].upcase }}Formatter"
          formatter = Formatter.const_get(formatter_class_name).new
        end
        Array(klass).each do |k|
          if k.class == Module
            @module_formatters[k] = formatter
          else
            k = k.name if k.is_a?(Class)
            @class_formatters[k] = formatter
          end
        end
      end
      self
    end
def add ( klass , formatter = nil , & block ) formatter ||= block if formatter . nil? remove ( klass ) else if formatter . is_a? ( Symbol ) formatter_class_name = "#{formatter.to_s.gsub(/(^|_)([a-z])/) { |m| $~[2].upcase }}Formatter" formatter = Formatter . const_get ( formatter_class_name ) . new end Array ( klass ) . each do | k | if k . class == Module @module_formatters [ k ] = formatter else k = k . name if k . is_a? ( Class ) @class_formatters [ k ] = formatter end end end self end
Add a formatter for a class.
Add a formatter for a class .
klass
formatter
block