Class: ObjectTracker::TrackerMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/object_tracker/tracker_method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, name) ⇒ TrackerMethod

Returns a new instance of TrackerMethod.



5
6
7
8
# File 'lib/object_tracker/tracker_method.rb', line 5

def initialize(context, name)
  @name = name
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/object_tracker/tracker_method.rb', line 3

def context
  @context
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/object_tracker/tracker_method.rb', line 3

def name
  @name
end

Instance Method Details

#display_nameObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/object_tracker/tracker_method.rb', line 21

def display_name
  return @display_name if defined? @display_name
  if Class === context || Module === context
    obj = context
    prefix = '.'
  elsif context.class === Class
    prefix = '.'
    obj = context.class
  else
    prefix = '#'
    obj = context.class
  end
  @display_name = "#{obj.name}#{prefix}#{@name}"
end

#sourceObject



10
11
12
13
14
# File 'lib/object_tracker/tracker_method.rb', line 10

def source
  return @source if defined? @source
  @source = source_location
  @source = @source ? @source.join(':').split('/').last(5).join('/') : 'RUBY CORE'
end

#source_locationObject



16
17
18
19
# File 'lib/object_tracker/tracker_method.rb', line 16

def source_location
  method_handle = context.method(name)
  method_handle.source_location if method_handle
end