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)


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

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.



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

def c_module?
  if 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
end

#command?Boolean

Returns:

  • (Boolean)


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

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

#module_with_yard_docs?Boolean

Returns:

  • (Boolean)


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

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)


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

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