Method calling to Proc, want to confirm I understand

Apologies, cause I’m trying to wrap my brain around this code and I have
some questions about it.
1- It seems that until ‘block.call’ what is getting passed into the
method
parameters is being held in que (so to speak). Or is that a wrong
interpreation.
2- How does the method know that it calls ‘25000 doublings’ first and
then
moves on to ‘count to a million’. I realize part of it is how the code
is
layed out but why couldn’t it just try the 25000 doublings again ?

Hope these type of questions are okay here.

TIA
Stuart

def profile block_description, &block
start_time = Time.now
block.call
duration = Time.now - start_time
puts block_description+’ : ’ +duration.to_s+’ seconds’
end

profile ‘25000 doublings’ do
number = 1
25000.times do
number = number + number
end

puts number.to_s.length.to_s+’ digits’

That’s the number of digits in this HUGE number.

end

profile ‘count to a million’ do
number = 0
1000000.times do
number = number + 1
end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs