Skip to content

Instantly share code, notes, and snippets.

@tagomoris
Created October 24, 2016 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tagomoris/7bca9fe4fdc3201f691094e6aad3b177 to your computer and use it in GitHub Desktop.
Save tagomoris/7bca9fe4fdc3201f691094e6aad3b177 to your computer and use it in GitHub Desktop.
# 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
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