Class: Fmt::NativeRegistry

Inherits:
Registry show all
Defined in:
lib/fmt/registries/native_registry.rb

Overview

Extends native Ruby String format specifications with native Ruby methods

Constant Summary collapse

SUPPORTED_CLASSES =
[
  Array,
  Date,
  DateTime,
  FalseClass,
  Float,
  Hash,
  Integer,
  NilClass,
  Range,
  Regexp,
  Set,
  StandardError,
  String,
  Struct,
  Symbol,
  Time,
  TrueClass
].freeze

Instance Method Summary collapse

Methods inherited from Registry

#add, #any?, #delete, #fetch, #key_for, #merge!, #none?, #with_overrides

Constructor Details

#initializeNativeRegistry

Constructor



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fmt/registries/native_registry.rb', line 30

def initialize
  super

  format = ->(*args, **kwargs) do
    verbose = $VERBOSE
    $VERBOSE = nil
    Kernel.sprintf(self, *args, **kwargs)
  ensure
    $VERBOSE = verbose
  end

  add([Kernel, :format], &format)
  add([Kernel, :sprintf], &format)

  SUPPORTED_CLASSES.each do |klass|
    supported_method_names(klass).each do |name|
      add([klass, name]) { |*args, **kwargs| public_send(name, *args, **kwargs) }
    end
  end
rescue => error
  puts "#{self.class.name} - Error adding filters! #{error.inspect}"
end