Module: Kernel

Defined in:
lib/fancy-p/kernel_ext.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/fancy-p/kernel_ext.rb', line 4

def method_missing(method_name, *args, &block)
  super unless method_name.to_s =~ /^p.$/

  define_singleton_method(method_name) do |*forwarded_args|
    char = method_name.to_s[1]
    fp(char, *forwarded_args)
  end
  send(method_name, *args)
end

Instance Method Details

#fp(str, *args, length: 100) ⇒ Object



14
15
16
17
18
19
# File 'lib/fancy-p/kernel_ext.rb', line 14

def fp(str, *args, length: 100)
  delimiter = str * length
  puts delimiter
  p(*args)
  puts delimiter
end

#fp_define(str, length: 100, method_name: str.strip) ⇒ Object



27
28
29
30
31
# File 'lib/fancy-p/kernel_ext.rb', line 27

def fp_define(str, length: 100, method_name: str.strip)
  define_singleton_method("fp_#{method_name.strip}") do |*args|
    fp(str, *args, length:)
  end
end

#fp_factory(str, length: 100) ⇒ Object



21
22
23
24
25
# File 'lib/fancy-p/kernel_ext.rb', line 21

def fp_factory(str, length: 100)
  lambda { |*args|
    fp(str, *args, length:)
  }
end