Mercurial > repos > tabletprog
comparison samples/reflect.tp @ 270:b74956a2196f
Add a propertiesOf method to the object module that returns the names of things that look like getter messages
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 18 Jul 2014 20:45:50 -0700 |
parents | 123e9468d55e |
children |
comparison
equal
deleted
inserted
replaced
269:632667d95d35 | 270:b74956a2196f |
---|---|
1 #{ | 1 #{ |
2 main <- { | 2 main <- { |
3 print: (string: (object does: 42 understand?: "+")) . "\n" | 3 o <- #{ |
4 print: (string: (object does: 42 understand?: "foobar")) . "\n" | 4 foo <- 42 |
5 foreach: (object understoodBy: 42) :idx el{ | 5 bar <- 39 |
6 doStuff <- :blah { | |
7 foo <- bar * blah | |
8 foo | |
9 } | |
10 qux <- { 1337 } | |
11 + <- :right { | |
12 foo + right | |
13 } | |
14 } | |
15 print: (string: (object does: o understand?: "+")) . "\n" | |
16 print: (string: (object does: o understand?: "foobar")) . "\n" | |
17 print: (string: (object sendMessage: "qux" to: o)) . "\n" | |
18 print: "Messages understood:\n" | |
19 foreach: (object understoodBy: o) :idx el{ | |
6 print: el . "\n" | 20 print: el . "\n" |
7 } | 21 } |
8 print: (object sendMessage: "hex" to: 42) . "\n" | 22 print: "\nProperties of:\n" |
23 foreach: (object propertiesOf: o) :idx el{ | |
24 print: el . "\n" | |
25 } | |
9 0 | 26 0 |
10 } | 27 } |
11 } | 28 } |