-
Notifications
You must be signed in to change notification settings - Fork 1
/
person-1.reb
61 lines (49 loc) · 1.32 KB
/
person-1.reb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Rebol [
Title: "Person Ported From Juixe.com Tutorial"
Description: {
Very early test of multiple attr_accessor, to_s,
and some starting work, adapted from the website:
http://juixe.com/techknow/index.php/2007/01/22/ruby-class-tutorial/
The original code didn't make it quite clear to me what the object
lifetime was, so I'll have to look into that.
}
]
; Include the code that makes Rebol act more like Ruby
do %rubol.reb
class Person [
attr_accessor [.fname .lname]
def initialize [fname lname] [
.fname: fname
.lname: lname
]
def to_s (nil) [
to-string compose [(.lname) ", " (.fname)]
]
; Not ready yet, just prototyping? Where do we put the "self" tag on
; class methods as opposed to instance methods? ObjectSpace/etc.
comment [
def find_by_name [fname] [
found: nil
foreach o (ObjectSpace Person) [
if o/fname == fname [
found: o
]
]
found
]
]
]
matz: Person/new["Yukihiro" "Matsumoto"]
; class name is working
puts matz/class/name
; so is calling the to_s member
puts matz
; why did the demo seem unconcerned about the garbage collection of these?
Person/new["David" "Thomas"]
Person/new["David" "Black"]
Person/new["Bruce" "Tate"]
; NOTE: Need to implement ObjectSpace concept not yet worked out
comment [
; Find matz!
puts Person/find_by_fname["Yukihiro"]
]