# Proc&Bloc

**URL:** <https://www.ruby-forum.com/t/proc-bloc/91706>\
**Category:** Ruby\
**Created:** [April 11, 2007, 7:43pm UTC](https://www.ruby-forum.com/t/proc-bloc/91706 "2007-04-11T19:43:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yaya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/cdc98d/32.png) [@yaya](https://www.ruby-forum.com/u/yaya)\
**Post date:** [April 11, 2007, 7:43pm UTC](https://www.ruby-forum.com/t/proc-bloc/91706/1 "2007-04-11T19:43:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yaya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/cdc98d/32.png) [@yaya](https://www.ruby-forum.com/u/yaya)\
**Post date:** [April 11, 2007, 8:27pm UTC](https://www.ruby-forum.com/t/proc-bloc/91706/2 "2007-04-11T20:27:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![yaya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/cdc98d/32.png) [@yaya](https://www.ruby-forum.com/u/yaya)\
**Post date:** [April 11, 2007, 11:55pm UTC](https://www.ruby-forum.com/t/proc-bloc/91706/3 "2007-04-11T23:55:07Z")

</div>

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:0x0c373dac@:2(irb)  
irb(main):005:0\> times5 = gen\_times(5)  
=\> #Proc:0x0c373dac@: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\>
