repo.or.cz
/
nyuron.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
history
|
raw
|
HEAD
made it work, more or less, with ruby 1.9
[nyuron.git]
/
modules
/
enumerable.rb
blob
eec780661b4feaceeda58c63ca0a3800880ad93a
1
class Void; end
2
3
module Enumerable
4
## a shortcut for map {...}
5
## [10, 20, 30].all + 5 => [15, 25, 35]
6
## [10, 20, 30].map { |x| x + 5 } => [15, 25, 35]
7
## %w(hello you).all.upcase => ["HELLO", "YOU"]
8
9
def all
10
Mapper.new(self)
11
end
12
13
## This class is used in Enumerable#all
14
class Mapper < Void
15
def initialize(obj)
16
@obj = obj
17
end
18
def method_missing(*args)
19
@obj.map do |item|
20
item.send(*args)
21
end
22
end
23
end
24
end
25