Skip to content

Instantly share code, notes, and snippets.

@nurse
Last active October 24, 2016 18:59
Show Gist options
  • Save nurse/c985a28811631980cba1016ce1296550 to your computer and use it in GitHub Desktop.
Save nurse/c985a28811631980cba1016ce1296550 to your computer and use it in GitHub Desktop.
% ruby --disable-gems test.rb
{:T_HASH=>1, :T_DATA=>2}
{:T_ARRAY=>1, :T_HASH=>1, :T_DATA=>1}
def myroot2(&block)
myfunc2(Time.now, {"a"=>1, "b"=>2}, &block)
end
def myfunc2(time, record)
yield time, record
end
def myroot1
time, record = myfunc1(Time.now, {"a"=>1, "b"=>2})
yield time, record
end
def myfunc1(time, record)
return time, record
end
h0={}
h1={}
h2={}
ObjectSpace.count_objects(h0)
GC.disable
ObjectSpace.count_objects(h0)
#p :block_and_yield
myroot2{|t,r| t; r; 1}
ObjectSpace.count_objects(h1)
#p :multi_value_return
myroot1{|t,r| t; r; 1}
ObjectSpace.count_objects(h2)
p h1.keys.map{|k|[k,h1[k]-h0[k]]}.select{|(a,b)|b>0}.to_h
p h1.keys.map{|k|[k,h2[k]-h1[k]]}.select{|(a,b)|b>0}.to_h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment