-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobj_12.rb
More file actions
executable file
·49 lines (41 loc) · 808 Bytes
/
robj_12.rb
File metadata and controls
executable file
·49 lines (41 loc) · 808 Bytes
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
#!/usr/bin/env ruby
require "./ruler"
#-----------------------------------------------------------------------------
R("Proc example")
p = Proc.new do
puts "something"
end
p.call
#-----------------------------------------------------------------------------
R("proc");
array = [ 1, 2, 3, 4 ]
oper = proc { |n, n2| 2*n + n2 }
a = oper.call(1, 3)
puts "2*n+n2 = #{a}"
sum_a = proc { |*sum|
ret = 0
sum.each do |elem|
ret += elem
end
ret
}
sum = sum_a.call(1, 2, 3)
puts "sum = #{sum}"
#-----------------------------------------------------------------------------
#R("pass a procedure")
#
#def filter(a, fi)
# filtered = []
# a.each do |a_item|
# if fi(a_item)
# filtered.push(a_item)
# end
# end
# filtered
#end
#
#filt = Proc.new {
# puts "#{n}"
#}
#
#filter([1, 5, 2, 4, 6, 3, 7], filt)