Parent

Pry::WrappedModule

Public Class Methods

new(mod) click to toggle source

Create a new WrappedModule @raise ArgumentError, if the argument is not a Module @param [Module]

# File lib/pry/wrapped_module.rb, line 10
def initialize(mod)
  raise ArgumentError, "Tried to initialize a WrappedModule with a non-module #{mod.inspect}" unless ::Module === mod
  @wrapped = mod
end

Public Instance Methods

method_missing(method_name, *args, &block) click to toggle source

Forward method invocations to the wrapped module

# File lib/pry/wrapped_module.rb, line 65
def method_missing(method_name, *args, &block)
  wrapped.send(method_name, *args, &block)
end
method_prefix() click to toggle source

The prefix that would appear before methods defined on this class.

i.e. the "String." or "String#" in String.new and String#initialize.

@return String

# File lib/pry/wrapped_module.rb, line 20
def method_prefix
  if singleton_class?
    if Module === singleton_instance
      "#{WrappedModule.new(singleton_instance).nonblank_name}."
    else
      "self."
    end
  else
    "#{nonblank_name}#"
  end
end
nonblank_name() click to toggle source

The name of the Module if it has one, otherwise #<Class:0xf00>.

@return [String]

# File lib/pry/wrapped_module.rb, line 35
def nonblank_name
  if name.to_s == ""
    wrapped.inspect
  else
    name
  end
end
respond_to?(method_name) click to toggle source
# File lib/pry/wrapped_module.rb, line 69
def respond_to?(method_name)
  super || wrapped.send(method_name, *args, &block)
end
singleton_class?() click to toggle source

Is this a singleton class? @return [Boolean]

# File lib/pry/wrapped_module.rb, line 45
def singleton_class?
  wrapped != wrapped.ancestors.first
end
singleton_instance() click to toggle source

Get the instance associated with this singleton class.

@raise ArgumentError: tried to get instance of non singleton class

@return [Object]

# File lib/pry/wrapped_module.rb, line 54
def singleton_instance
  raise ArgumentError, "tried to get instance of non singleton class" unless singleton_class?

  if Helpers::BaseHelpers.jruby?
    wrapped.to_java.attached
  else
    @singleton_instance ||= ObjectSpace.each_object(wrapped).detect{ |x| (class << x; self; end) == wrapped }
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.