Module: Pry::CodeObject::Helpers

Included in:
Pry::Command, Method, WrappedModule, WrappedModule::Candidate
Defined in:
lib/pry/code_object.rb

Instance Method Summary collapse

Instance Method Details

#c_method?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/pry/code_object.rb', line 30

def c_method?
  real_method_object? && source_type == :c
end

#c_module?Boolean

Note:

If a module defined by C was extended with a lot of methods written in Ruby, this method would fail.

Returns ‘true` if this module was defined by means of the C API, `false` if it’s a Ruby module.

Returns:

  • (Boolean)

    ‘true` if this module was defined by means of the C API, `false` if it’s a Ruby module.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/pry/code_object.rb', line 46

def c_module?
  return unless is_a?(WrappedModule)

  method_locations = wrapped.methods(false).map do |m|
    wrapped.method(m).source_location
  end

  method_locations.concat(
    wrapped.instance_methods(false).map do |m|
      wrapped.instance_method(m).source_location
    end
  )

  c_methods = method_locations.grep(nil).count
  ruby_methods = method_locations.count - c_methods

  c_methods > ruby_methods
end

#command?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/pry/code_object.rb', line 38

def command?
  is_a?(Module) && self <= Pry::Command
end

#module_with_yard_docs?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/pry/code_object.rb', line 34

def module_with_yard_docs?
  is_a?(WrappedModule) && yard_docs?
end

#real_method_object?Boolean

we need this helper as some Pry::Method objects can wrap Procs

Returns:

  • (Boolean)


26
27
28
# File 'lib/pry/code_object.rb', line 26

def real_method_object?
  is_a?(::Method) || is_a?(::UnboundMethod)
end