module Tapioca::Reflection

Constants

ANCESTORS_METHOD
CLASS_METHOD
CONSTANTS_METHOD
EQUAL_METHOD
NAME_METHOD
OBJECT_ID_METHOD
PRIVATE_INSTANCE_METHODS_METHOD
PROTECTED_INSTANCE_METHODS_METHOD
PUBLIC_INSTANCE_METHODS_METHOD
SINGLETON_CLASS_METHOD
SUPERCLASS_METHOD

Public Instance Methods

ancestors_of(constant) click to toggle source
# File lib/tapioca/reflection.rb, line 42
def ancestors_of(constant)
  ANCESTORS_METHOD.bind(constant).call
end
are_equal?(object, other) click to toggle source
# File lib/tapioca/reflection.rb, line 57
def are_equal?(object, other)
  EQUAL_METHOD.bind(object).call(other)
end
class_of(object) click to toggle source
# File lib/tapioca/reflection.rb, line 22
def class_of(object)
  CLASS_METHOD.bind(object).call
end
constants_of(constant) click to toggle source
# File lib/tapioca/reflection.rb, line 27
def constants_of(constant)
  CONSTANTS_METHOD.bind(constant).call(false)
end
descendants_of(klass) click to toggle source
# File lib/tapioca/reflection.rb, line 123
def descendants_of(klass)
  result = ObjectSpace.each_object(klass.singleton_class).reject do |k|
    T.cast(k, Module).singleton_class? || T.unsafe(k) == klass
  end

  T.unsafe(result)
end
inherited_ancestors_of(constant) click to toggle source
# File lib/tapioca/reflection.rb, line 77
def inherited_ancestors_of(constant)
  if Class === constant
    ancestors_of(superclass_of(constant) || Object)
  else
    Module.ancestors
  end
end
name_of(constant) click to toggle source
# File lib/tapioca/reflection.rb, line 32
def name_of(constant)
  NAME_METHOD.bind(constant).call
end
name_of_type(type) click to toggle source
# File lib/tapioca/reflection.rb, line 105
def name_of_type(type)
  type.to_s.gsub(/\bAttachedClass\b/, "T.attached_class")
end
object_id_of(object) click to toggle source
# File lib/tapioca/reflection.rb, line 52
def object_id_of(object)
  OBJECT_ID_METHOD.bind(object).call
end
private_instance_methods_of(constant) click to toggle source
# File lib/tapioca/reflection.rb, line 72
def private_instance_methods_of(constant)
  PRIVATE_INSTANCE_METHODS_METHOD.bind(constant).call
end
protected_instance_methods_of(constant) click to toggle source
# File lib/tapioca/reflection.rb, line 67
def protected_instance_methods_of(constant)
  PROTECTED_INSTANCE_METHODS_METHOD.bind(constant).call
end
public_instance_methods_of(constant) click to toggle source
# File lib/tapioca/reflection.rb, line 62
def public_instance_methods_of(constant)
  PUBLIC_INSTANCE_METHODS_METHOD.bind(constant).call
end
qualified_name_of(constant) click to toggle source
# File lib/tapioca/reflection.rb, line 86
def qualified_name_of(constant)
  name = name_of(constant)
  return if name.nil?

  if name.start_with?("::")
    name
  else
    "::#{name}"
  end
end
signature_of(method) click to toggle source
# File lib/tapioca/reflection.rb, line 98
def signature_of(method)
  T::Private::Methods.signature_for_method(method)
rescue LoadError, StandardError
  nil
end
singleton_class_of(constant) click to toggle source
# File lib/tapioca/reflection.rb, line 37
def singleton_class_of(constant)
  SINGLETON_CLASS_METHOD.bind(constant).call
end
superclass_of(constant) click to toggle source
# File lib/tapioca/reflection.rb, line 47
def superclass_of(constant)
  SUPERCLASS_METHOD.bind(constant).call
end