Class: PryMoves::TracedMethod

Inherits:
Hash
  • Object
show all
Defined in:
lib/commands/traced_method.rb

Constant Summary collapse

@@last =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(binding_) ⇒ TracedMethod

Returns a new instance of TracedMethod.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/commands/traced_method.rb', line 8

def initialize(binding_)
  super()

  method = find_method_definition binding_
  if method
    source = method.source_location
    set_method({
      file: source[0],
      start: source[1],
      name: method.name,
      end: (source[1] + method.source.count("\n") - 1)
    })
  else
    set_method({file: binding_.eval('__FILE__')})
  end
end

Class Method Details

.lastObject



4
5
6
# File 'lib/commands/traced_method.rb', line 4

def self.last
  @@last
end

Instance Method Details

#before_end?(line) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/commands/traced_method.rb', line 38

def before_end?(line)
  self[:end] and line < self[:end]
end

#binding_inside?(binding) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/commands/traced_method.rb', line 34

def binding_inside?(binding)
  within? *binding.eval('[__FILE__, __LINE__, __method__]')
end

#within?(file, line, id = nil) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
# File 'lib/commands/traced_method.rb', line 25

def within?(file, line, id = nil)
  return unless self[:file] == file
  return unless self[:start].nil? or
    line.between?(self[:start], self[:end])
  return unless id.nil? or self[:name] == id # fix for bug in traced_method: return for dynamic methods has line number inside of caller

  true
end