at:tutorial:objects
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
at:tutorial:objects [2007/07/18 18:09] – jorge | at:tutorial:objects [2007/07/18 18:28] – jorge | ||
---|---|---|---|
Line 159: | Line 159: | ||
def Enumerable := object: { | def Enumerable := object: { | ||
def collect: closure { | def collect: closure { | ||
- | def c := self.new(); | + | def c := self.new([]); |
self.each: { |v| | self.each: { |v| | ||
- | closure(v); | + | |
}; | }; | ||
+ | c; | ||
}; | }; | ||
}; | }; | ||
Line 173: | Line 174: | ||
def each: clo { | def each: clo { | ||
1.to: elements.length + 1 do: { |i| | 1.to: elements.length + 1 do: { |i| | ||
- | | + | clo(elements[i]); |
}; | }; | ||
}; | }; | ||
Line 186: | Line 187: | ||
> def c := Array.collect: | > def c := Array.collect: | ||
>> < | >> < | ||
- | > c.each: { |v| system.println(v)} | + | > c.each: { |v| system.print(v)} |
2 | 2 | ||
3 | 3 |
at/tutorial/objects.txt · Last modified: 2013/05/17 20:23 by tvcutsem