Class: TCOMethod::MethodInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/tco_method/method_info.rb

Overview

Class encapsulating the behaviors required to extract information about a method from the 14-element Array of data representing the instruction sequence of that method.

Constant Summary collapse

VALID_METHOD_CLASSES =

A collection of those classes that will be recognized as methods and can be used effectively with this class.

[
  Method,
  UnboundMethod,
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(method_obj) ⇒ MethodInfo

Creates a new MethodInfo instance.

Parameters:

  • method_obj (Method)

    The Method or UnboundMethod object representing the method for which more information should be retrieved.

Raises:

  • (TypeError)

    Raised if the provided method object is not a Method or Unbound method.

See Also:



20
21
22
23
24
25
26
# File 'lib/tco_method/method_info.rb', line 20

def initialize(method_obj)
  unless VALID_METHOD_CLASSES.any? { |klass| method_obj.is_a?(klass) }
    msg = "Invalid argument! Method or UnboundMethod expected, received #{method_obj.class.name}"
    raise TypeError, msg
  end
  @info = RubyVM::InstructionSequence.of(method_obj).to_a
end

Instance Method Details

#typeSymbol

Returns the type of the method object as reported by the Array of data describing the instruction sequence representing the method.

Returns:

  • (Symbol)

    A Symbol identifying the type of the instruction sequence. Typical values will be :method or :block, but all of the following are valid return values: :top, :method, :block, :class, :rescue, :ensure, :eval, :main, and :defined_guard.



35
36
37
# File 'lib/tco_method/method_info.rb', line 35

def type
  @info[9]
end