Why isn't Ruby Tracepoint tracking calls to methods like `String#size`?

I’d like to track all method calls made in a program I’m writing using
Tracepoint. For the most part, Tracepoint is working as expected, but
there are cases where it doesn’t. For instance, having a String#size
call doesn’t track the call. Why is that?

Example:

class A
def initialize
@size = nil
end

def call_to_method_a
@size = ‘test’.size
say_size
end

def say_size
puts @size
end
end

TracePoint.trace(:call, :c_call) do |tp|
p [tp.lineno, tp.defined_class, tp.method_id, tp.event]
end

A.new.call_to_method_a


Output running the above:

[45, Class, :new, :c_call]
[27, A, :initialize, :call]
[31, A, :call_to_method_a, :call]
[36, A, :say_size, :call]
[37, Kernel, :puts, :c_call]
[37, IO, :puts, :c_call]
[37, Fixnum, :to_s, :c_call]
[37, IO, :write, :c_call]
4[37, IO, :write, :c_call]

Missing is anything related to String#size. I’m using Ruby 2.3.0.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs