# Proc&Bloc

Hi
I start learning ruby since a week but i have some probleme to undestand
Proc
and the philosophy which hides behind .
Why don’t using methode ?
In this code vhere is the Proc?

``````    def gen_times(factor)
return Proc.new {|n| n*factor }
end

times3 = gen_times(3)
times5 = gen_times(5)

times3.call(12)               #=> 36
times5.call(5)                #=> 25
times3.call(times5.call(4))   #=> 60
``````

Really it do not arrive to undertand

Try your code again in irb.
then, in irb
times3.class

Should give you the answer.

Proc

When you def gen_times, actually, you are telling how to create an
instance of Proc with a code block. gen_times’s code block happens to
take the factor and multiply it by n
this is like a function object.

If you’ve only been at it one week, don’t worry. It will become clear!

Hi Thank
I see what is the probleme

irb(main):001:0> def gen_times(factor)
irb(main):002:1> return Proc.new {|n| n*factor }
irb(main):003:1> end
=> nil
irb(main):004:0> times3 = gen_times(3)
=> #Proc:[email protected]:2(irb)
irb(main):005:0> times5 = gen_times(5)
=> #Proc:[email protected]:2(irb)
irb(main):006:0> times3.call(12)
=> 36
irb(main):007:0> times5.call(5)
=> 25
irb(main):008:0> times3.call(times5.call(4))
=> 60
irb(main):009:0>