W
Wilson Bilkovich
Code using attr_accessor:
class User
attr_accessor :something
def initialize
@something = 0
end
end
@user = User.new
set_trace_func(lambda {|*trace| STDERR.puts trace.inspect})
@user.something
#########
prints this to STDERR:
["line", "trace_func.rb", 11, nil, #<Binding:0x2946df0>, false]
#########
Functionally equivalent code with a hand-written method, instead of
attr_accessor:
class User
def something
@something
end
def initialize
@something = 0
end
end
@user = User.new
set_trace_func(lambda {|*trace| STDERR.puts trace.inspect})
@user.something
#########
prints this to STDERR:
["line", "trace_func.rb", 13, nil, #<Binding:0x2946d78>, false]
["call", "trace_func.rb", 2, :something, #<Binding:0x2946c10>, User]
["line", "trace_func.rb", 3, :something, #<Binding:0x2946bc8>, User]
["return", "trace_func.rb", 4, :something, #<Binding:0x2946aa8>, User]
#########
How can I capture the fact that the 'something' accessor was called in
the first example?
class User
attr_accessor :something
def initialize
@something = 0
end
end
@user = User.new
set_trace_func(lambda {|*trace| STDERR.puts trace.inspect})
@user.something
#########
prints this to STDERR:
["line", "trace_func.rb", 11, nil, #<Binding:0x2946df0>, false]
#########
Functionally equivalent code with a hand-written method, instead of
attr_accessor:
class User
def something
@something
end
def initialize
@something = 0
end
end
@user = User.new
set_trace_func(lambda {|*trace| STDERR.puts trace.inspect})
@user.something
#########
prints this to STDERR:
["line", "trace_func.rb", 13, nil, #<Binding:0x2946d78>, false]
["call", "trace_func.rb", 2, :something, #<Binding:0x2946c10>, User]
["line", "trace_func.rb", 3, :something, #<Binding:0x2946bc8>, User]
["return", "trace_func.rb", 4, :something, #<Binding:0x2946aa8>, User]
#########
How can I capture the fact that the 'something' accessor was called in
the first example?