Class: Configurations::BlankObject

Inherits:
BasicObject
Defined in:
lib/configurations/blank_object.rb

Overview

Create a blank object with some kernel methods

Direct Known Subclasses

Configuration

Constant Summary collapse

KEEP_METHODS =

The instance methods to keep on the blank object.

[
  :equal?,
  :object_id,
  :__id__,
  :__instance_variables__,
  :__send__,
  :method_missing
].freeze
ALIAS_KERNEL_METHODS =

The kernel methods to alias to an internal name

{
  __class__: :class,
  __instance_eval__: :instance_eval,
  __define_singleton_method__: :define_singleton_method
}.freeze
KEEP_KERNEL_METHODS =

The kernel methods to keep on the blank object

[
  :respond_to?,
  :is_a?,
  :inspect,
  :to_s,
  :object_id,
  # rbx needs the singleton class to access singleton methods
  :singleton_class,
  # rbx needs its private methods
  :__instance_variable_defined_p__,
  :__instance_variable_get__,
  :__instance_variable_set__,
  :__instance_variable__,
  *ALIAS_KERNEL_METHODS.keys
].compact.freeze

Class Method Summary collapse

Class Method Details

.blank_kernelModule

Returns A Kernel module with only the methods defined in KEEP_KERNEL_METHODS.

Returns:

  • (Module)

    A Kernel module with only the methods defined in KEEP_KERNEL_METHODS


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/configurations/blank_object.rb', line 51

def self.blank_kernel
  kernel = ::Kernel.dup

  ALIAS_KERNEL_METHODS.each do |new_name, old_name|
    kernel.module_eval { alias_method new_name, old_name }
  end

  (kernel.instance_methods - KEEP_KERNEL_METHODS).each do |method|
    kernel.module_eval { undef_method method }
  end

  kernel
end