Skip to content

Commit 2da325e

Browse files
committed
yay protected and private
1 parent 23b05f9 commit 2da325e

3 files changed

Lines changed: 2584 additions & 11 deletions

File tree

‎v4-cokapi/backends/ruby/pg_logger.rb‎

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
# first deployed on 2015-07-15
44
#
55
# WARNING: this script only works on a *hacked version* of Ruby 2.X since
6-
# we use the TracePoint API and custom fields such as binding::frame_id.
6+
# we use the TracePoint API (standard in 2.X) and custom fields such as
7+
# binding::frame_id (only available in our hacked version).
78
# See custom-ruby-interpreter/ for details.
89

9-
# simple Ruby idiom for assert:
10-
# raise "error msg" unless <condition to assert>
11-
1210
# TODO
1311
#
1412
# - display the 'binding' within a proc/lambda object, which represents
@@ -17,18 +15,14 @@
1715
# - support gets() for taking user input using the restart hack mechanism
1816
# that we used for Python. user input stored in $_
1917
#
20-
# - properly display private and protected attributes
21-
#
2218
# Limitations/quirks:
2319
# - no support yet for (lexical) environment pointers, since MRI doesn't
2420
# seem to expose them. We can see only the current (dynamic) stack
2521
# backtrace with debug_inspector.
2622
# - NB: is this true? at least we have 'binding' for procs/lambdas
2723
#
28-
# - it keeps executing for a few more lines after an exception -- dunno if
29-
# that's standard Ruby behavior or not
30-
#
31-
# - method aliases show up as separate Method objects instead of the same one
24+
# - code keeps executing for a few more lines after an exception;
25+
# dunno if that's standard Ruby behavior or not
3226
#
3327
# - if you write, say, "require 'date'", it will pull in classes from
3428
# the date module into globals, which might make the display HUGE
@@ -202,7 +196,14 @@ def encode(dat)
202196
encoded_class_methods << ['self.' + e.to_s, encode(dat.method(e))]
203197
end
204198

205-
dat.instance_methods.each do |e|
199+
# apparently there are no protected class methods
200+
my_private_class_methods = dat.private_methods - dat.superclass.private_methods
201+
my_private_class_methods.each do |e|
202+
encoded_class_methods << ['self.' + e.to_s + ' [private]', encode(dat.method(e))]
203+
end
204+
205+
# separately handle public, protected, and private
206+
dat.public_instance_methods.each do |e|
206207
m = dat.instance_method(e)
207208
# only add if this method belongs to YOU and not to a superclass
208209
if m.owner == dat
@@ -211,6 +212,18 @@ def encode(dat)
211212
encoded_instance_methods << [e.to_s, encode(m)]
212213
end
213214
end
215+
dat.protected_instance_methods.each do |e|
216+
m = dat.instance_method(e)
217+
if m.owner == dat
218+
encoded_instance_methods << [e.to_s + ' [protected]', encode(m)]
219+
end
220+
end
221+
dat.private_instance_methods.each do |e|
222+
m = dat.instance_method(e)
223+
if m.owner == dat
224+
encoded_instance_methods << [e.to_s + ' [private]', encode(m)]
225+
end
226+
end
214227

215228
dat.class_variables.each do |e|
216229
encoded_class_variables << [e.to_s, encode(dat.class_variable_get(e))]

0 commit comments

Comments
 (0)