Module: Kernel

Includes:
LateKernel
Included in:
Pry::BasicObject
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/preload.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/lib/blankslate.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/minitest-5.17.0/lib/minitest/spec.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/core_ext/kernel/concern.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/core_ext/kernel/reporting.rb,
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/core_ext/kernel/singleton_class.rb

Overview

Introduce some late methods (both module and direct) into the Kernel module.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LateKernel

included, #late_kernel

Class Attribute Details

.k_added_namesObject (readonly)

Returns the value of attribute k_added_names.



20
21
22
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/preload.rb', line 20

def k_added_names
  @k_added_names
end

Class Method Details

.blank_slate_method_addedObject



86
87
88
89
90
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/lib/blankslate.rb', line 86

def method_added(name)
  preload_method_added(name)
  @k_added_names ||= []
  @k_added_names << name
end

.concern(topic, &module_definition) ⇒ Object

A shortcut to define a toplevel concern, not within a module.

See Module::Concerning for more.



11
12
13
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/core_ext/kernel/concern.rb', line 11

def concern(topic, &module_definition)
  Object.concern topic, &module_definition
end

.enable_warnings(&block) ⇒ Object

Sets $VERBOSE to true for the duration of the block and back to its original value afterwards.



20
21
22
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/core_ext/kernel/reporting.rb', line 20

def enable_warnings(&block)
  with_warnings(true, &block)
end

.method_added(name) ⇒ Object

Detect method additions to Kernel and remove them in the BlankSlate class.



90
91
92
93
94
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/lib/blankslate.rb', line 90

def method_added(name)
  preload_method_added(name)
  @k_added_names ||= []
  @k_added_names << name
end

.preload_method_addedObject



21
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/preload.rb', line 21

alias_method :preload_method_added, :method_added

.silence_warnings(&block) ⇒ Object

Sets $VERBOSE to nil for the duration of the block and back to its original value afterwards.

silence_warnings do
  value = noisy_call # no warning voiced
end

noisy_call # warning voiced


14
15
16
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/core_ext/kernel/reporting.rb', line 14

def silence_warnings(&block)
  with_warnings(nil, &block)
end

.suppress(*exception_classes) ⇒ Object

Blocks and ignores any exception passed as argument if raised within the block.

suppress(ZeroDivisionError) do
  1/0
  puts 'This code is NOT reached'
end

puts 'This code gets executed and nothing related to ZeroDivisionError was seen'


41
42
43
44
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/core_ext/kernel/reporting.rb', line 41

def suppress(*exception_classes)
  yield
rescue *exception_classes
end

.with_warnings(flag) ⇒ Object

Sets $VERBOSE for the duration of the block and back to its original value afterwards.



26
27
28
29
30
31
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/core_ext/kernel/reporting.rb', line 26

def with_warnings(flag)
  old_verbose, $VERBOSE = $VERBOSE, flag
  yield
ensure
  $VERBOSE = old_verbose
end

Instance Method Details

#class_eval(*args, &block) ⇒ Object

class_eval on an object acts like singleton_class.class_eval.



5
6
7
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4/lib/active_support/core_ext/kernel/singleton_class.rb', line 5

def class_eval(*args, &block)
  singleton_class.class_eval(*args, &block)
end

#double_late_additionObject



50
51
52
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 50

def double_late_addition
  22
end

#late_additionObject



46
47
48
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/builder-3.2.4/test/test_blankslate.rb', line 46

def late_addition
  1234
end