Created
October 24, 2016 10:13
-
-
Save tagomoris/7bca9fe4fdc3201f691094e6aad3b177 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# block and yield | |
[15] pry(main)> t = Time.now; 10_000_000.times{ myroot2{|t,r| t; r; 1} }; p(Time.now - t) | |
19.370526 | |
=> 19.370526 | |
# multi value return | |
[16] pry(main)> t = Time.now; 10_000_000.times{ myroot1{|t,r| t; r; 1} }; p(Time.now - t) | |
14.743976 | |
=> 14.743976 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def myroot1 | |
time, record = myfunc1(Time.now, {"a"=>1, "b"=>2}) | |
yield time, record | |
end | |
def myfunc1(time, record) | |
return time, record | |
end | |
def myroot2(&block) | |
myfunc2(Time.now, {"a"=>1, "b"=>2}, &block) | |
end | |
def myfunc2(time, record) | |
yield time, record | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment