|
12 | 12 | # TODO |
13 | 13 | # |
14 | 14 | # - display the 'binding' within a proc/lambda object, which represents |
15 | | -# https://codequizzes.wordpress.com/2014/04/07/rubys-self-keyword-and-implicit-self/ |
16 | | -# its closure. test on tests/proc-return.rb |
| 15 | +# its closure. see tests/proc-return.rb |
17 | 16 | # |
18 | 17 | # - support gets() for taking user input using the restart hack mechanism |
19 | 18 | # that we used for Python. user input stored in $_ |
|
36 | 35 | # with way too many attributes. this is a general problem that |
37 | 36 | # manifests in other languages as well. |
38 | 37 |
|
39 | | -# style guide: https://github.com/styleguide/ruby |
40 | | - |
41 | 38 |
|
42 | 39 | require 'json' |
43 | 40 | require 'optparse' |
@@ -198,16 +195,21 @@ def encode(dat) |
198 | 195 | encoded_constants << [e.to_s, encode(dat.const_get(e))] |
199 | 196 | end |
200 | 197 |
|
| 198 | + # TODO: what about if you override a class method that your |
| 199 | + # superclass defines? will we run into problems then? |
201 | 200 | my_class_methods = dat.methods - dat.superclass.methods |
202 | 201 | my_class_methods.each do |e| |
203 | 202 | encoded_class_methods << ['self.' + e.to_s, encode(dat.method(e))] |
204 | 203 | end |
205 | 204 |
|
206 | | - my_instance_methods = dat.instance_methods - dat.superclass.instance_methods |
207 | | - my_instance_methods.each do |e| |
208 | | - # use instance_method to get the unbound method |
209 | | - # http://ruby-doc.org/core-2.2.0/UnboundMethod.html |
210 | | - encoded_instance_methods << [e.to_s, encode(dat.instance_method(e))] |
| 205 | + dat.instance_methods.each do |e| |
| 206 | + m = dat.instance_method(e) |
| 207 | + # only add if this method belongs to YOU and not to a superclass |
| 208 | + if m.owner == dat |
| 209 | + # use instance_method to get the unbound method |
| 210 | + # http://ruby-doc.org/core-2.2.0/UnboundMethod.html |
| 211 | + encoded_instance_methods << [e.to_s, encode(m)] |
| 212 | + end |
211 | 213 | end |
212 | 214 |
|
213 | 215 | dat.class_variables.each do |e| |
|
0 commit comments