Hello friends,
Can anybody tell me the answer.
what is the uses of inject().
Give some example.
by
Vellingiri.
···
--
Posted via http://www.ruby-forum.com/.
Hello friends,
Can anybody tell me the answer.
what is the uses of inject().
Give some example.
by
Vellingiri.
--
Posted via http://www.ruby-forum.com/.
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
You have a lot of Q and what examples have a look in
http://www.ruby-doc.org/docs/UsersGuide/rg/
//AP
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-forum.com/.
Hello friends,
Can anybody tell me the answer.what is the uses of inject().
http://errtheblog.com/post/633
Give some example.
http://www.dtcc.edu/cs/rfc1855.html#3
A general hint: search engines can go a long way in helping answering questions.
Regards
robert
2007/9/19, Vellingiri Arul <hariharan.spc@rediffmail.com>:
anders wrote:
Hello friends,
Can anybody tell me the answer.what is the uses of inject().
Give some example.by
Vellingiri.
--
Posted viahttp://www.ruby-forum.com/.You have a lot of Q and what examples have a look in
http://www.ruby-doc.org/docs/UsersGuide/rg/
//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.
On 19 Sep, 12:06, Vellingiri Arul <hariharan....@rediffmail.com> > wrote:
--
Posted via http://www.ruby-forum.com/\.