Module: Kernel

Defined in:
lib/kernel.rb

Overview

Core Ruby module extended to provide the Defi method globally. This extension allows for convenient method encapsulation and delayed execution through the Defi method, accessible anywhere in the Ruby environment.

Instance Method Summary collapse

Instance Method Details

#Defi(method_name, *args, **opts, &block) ⇒ Defi::Method

Creates a new Defi::Method instance. This method provides a flexible way to encapsulate a method name along with its arguments, keyword arguments, and an optional block for later invocation.

Examples:

Basic method without arguments

Defi(:to_s)

Method with positional arguments

Defi(:+, 2)
Defi(:[], 0, 2)  # For array/string slicing

Method with keyword arguments

Defi(:transform, x: 1, y: 2)

Method with a block

Defi(:map) { |x| x * 2 }

Complex method call

Defi(:reduce, 0, &:+)  # Sum an array

Parameters:

  • method_name (Symbol)

    The method name to be sent to an object

  • args (Array)

    Positional arguments to be passed to the method

  • opts (Hash)

    Keyword arguments to be passed to the method

  • block (Proc)

    Optional block to be passed to the method

Returns:

  • (Defi::Method)

    An instance of Defi::Method encapsulating the method call

Raises:

  • (ArgumentError)

    If method_name is not a Symbol



40
41
42
# File 'lib/kernel.rb', line 40

def Defi(method_name, *args, **opts, &block)
  ::Defi::Method.new(method_name, *args, **opts, &block)
end