Sha256: 447ba9305f6b1179c3de6c9e489256382522290edcf93c859c4c7c4de3598a59

Contents?: true

Size: 1.03 KB

Versions: 23

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/patches/object/if_present'
require 'pp'

class Object
  def compact_debug(*methods_names)
    methods_names.each do |method_name|
      send(method_name).print_debug(label: method_name)
    end
  end

  def pretty_debug(options = {})
    print_debug_options(options)

    STDERR.write(pretty_inspect)

    self
  end

  def print_debug(options = {})
    print_debug_options(options)
    STDERR.write(to_debug + "\n")

    self
  end

  def print_debug_label(label)
    STDERR.write("#{label}: ")
  end

  def print_debug_options(options)
    options[:title].if_present { |v| print_debug_title(v) }
    options[:label].if_present { |v| print_debug_label(v) }
  end

  def print_debug_title(title)
    char = '='
    STDERR.write(char * (4 + title.length) + "\n")
    STDERR.write("#{char} #{title} #{char}\n")
    STDERR.write(char * (4 + title.length) + "\n")
  end

  def to_debug
    "|#{::Object.instance_method(:to_s).bind(self).call}|#{self}|"
  end

  def raise_debug
    raise to_debug
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
eac_tools-0.76.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.76.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.75.2 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_ruby_utils-0.119.2 lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.75.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.75.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_ruby_utils-0.119.1 lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.74.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.74.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.73.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_ruby_utils-0.119.0 lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.72.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_ruby_utils-0.118.1 lib/eac_ruby_utils/patches/object/debug.rb
eac_ruby_utils-0.118.0 lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.70.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.70.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.69.1 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_ruby_utils-0.117.1 lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.69.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb
eac_tools-0.68.0 sub/eac_ruby_utils/lib/eac_ruby_utils/patches/object/debug.rb