[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

what is the uses of inject

Vellingiri Arul

9/19/2007 10:07:00 AM

Hello friends,
Can anybody tell me the answer.

what is the uses of inject().
Give some example.

by
Vellingiri.
--
Posted via http://www.ruby-....

4 Answers

uap12

9/19/2007 10:51:00 AM

0

On 19 Sep, 12:06, Vellingiri Arul <hariharan....@rediffmail.com>
wrote:
> Hello friends,
> Can anybody tell me the answer.
>
> what is the uses of inject().
> Give some example.
>
> by
> Vellingiri.
> --
> Posted viahttp://www.ruby-....

You have a lot of Q and what examples have a look in
http://www.ruby-doc.org/docs/User...
//AP

Sebastian Hungerecker

9/19/2007 10:54:00 AM

0

Vellingiri Arul wrote:
> Hello friends,
> Can anybody tell me the answer.
> what is the uses of inject().

ri Enumerable#inject can give you a more elaborate answer, but here's mine:
It allows you to combine the elements of an array using a block (passing the
initial value or the result of the last iteration as well as the current item
to the block each iteration).


> Give some example.

[1,2,3,4].inject {|s,i| s+i}
#=> 10 (1+2+3+4)

some_string="haolaolai foo tadam tadum bar HuHu chunky lamb bacon"
regexen=[/la./,/foo.*bar/,/huhu/i]
regexen.inject(some_string) {|str,re| str.gsub(re,"")}
#=> "hao chunky b bacon"
#(same as some_string.gsub(/la./,"").gsub(/foo.*bar/,"").gsub(/huhu/i,"") )


HTH,
Sebastian
--
NP: Porcupine Tree - Deadwing
Jabber: sepp2k@jabber.org
ICQ: 205544826

Robert Klemme

9/19/2007 11:00:00 AM

0

2007/9/19, Vellingiri Arul <hariharan.spc@rediffmail.com>:
> Hello friends,
> Can anybody tell me the answer.
>
> what is the uses of inject().

http://errtheblog.co...

> Give some example.

http://www.dtcc.edu/cs/rfc1...

A general hint: search engines can go a long way in helping answering questions.

Regards

robert

Vellingiri Arul

9/19/2007 11:03:00 AM

0

anders wrote:
> On 19 Sep, 12:06, Vellingiri Arul <hariharan....@rediffmail.com>
> wrote:
>> Hello friends,
>> Can anybody tell me the answer.
>>
>> what is the uses of inject().
>> Give some example.
>>
>> by
>> Vellingiri.
>> --
>> Posted viahttp://www.ruby-....
>
> You have a lot of Q and what examples have a look in
> http://www.ruby-doc.org/docs/User...
> //AP

very very thank you friends.

You have asked one question know,that is not a example program question.
I am also working one software company,I have faced lot of doubts in my
ruby program.
Some thing general what we were discussed the questions.

Ok.

by

vellingiri.
--
Posted via http://www.ruby-....