Last change
on this file since 270 was 270, checked in by coas-nagasima, 7 years ago |
mruby版ECNLプロトタイピング・ツールを追加
|
-
Property svn:eol-style
set to
native
-
Property svn:mime-type
set to
text/x-ruby
|
File size:
743 bytes
|
Line | |
---|
1 | assert('Object#instance_exec') do
|
---|
2 | class KlassWithSecret
|
---|
3 | def initialize
|
---|
4 | @secret = 99
|
---|
5 | end
|
---|
6 | end
|
---|
7 | k = KlassWithSecret.new
|
---|
8 | assert_equal 104, k.instance_exec(5) {|x| @secret+x }
|
---|
9 | end
|
---|
10 |
|
---|
11 | assert('Object#tap') do
|
---|
12 | ret = []
|
---|
13 | (1..10) .tap {|x| ret << "original: #{x.inspect}"}
|
---|
14 | .to_a .tap {|x| ret << "array: #{x.inspect}"}
|
---|
15 | .select {|x| x%2==0} .tap {|x| ret << "evens: #{x.inspect}"}
|
---|
16 | .map { |x| x*x } .tap {|x| ret << "squares: #{x.inspect}"}
|
---|
17 |
|
---|
18 | assert_equal [
|
---|
19 | "original: 1..10",
|
---|
20 | "array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]",
|
---|
21 | "evens: [2, 4, 6, 8, 10]",
|
---|
22 | "squares: [4, 16, 36, 64, 100]"
|
---|
23 | ], ret
|
---|
24 | assert_equal(:tap_ok, Class.new {def m; tap{return :tap_ok}; end}.new.m)
|
---|
25 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.