Ruby on Rails
Thursday, August 29, 2013
Colin is right. You should try reading a book, like this one: http://pragprog.com/book/ruby4/programming-ruby-1-9-2-0
--
Dheeraj Kumar
On Friday 30 August 2013 at 2:12 AM, Colin Law wrote:
On 29 August 2013 21:40, Dheeraj Kumar <a.dheeraj.kumar@gmail.com> wrote:def array_sum(array1 = [], array2 = [])array1 + array2endarray_sum([1,2,3], [4,5,6])=> [1, 2, 3, 4, 5, 6]Also I suggest the OP works through a good Ruby primer.Colin--Dheeraj KumarOn Friday 30 August 2013 at 2:01 AM, Alex Froelich wrote:Hello again ruby community!I just learned how to add two arrays(I know, i know).My program looked like thisarray1=[1,2,3]array2=[4,5,6]array_sum=array1+array2I thought pretty simple stuff, they are combined. However, now i amlooking to define that code as a method and I do not understand how tocreate the correct number of arguments, so when the method is calledback it gives me my array_sum.I have been trying many different variations, but it has now come downto I am not sure if my defining is wrong or my code in the method isincorrect.I want to say it is something such asdef please_work()array1=[1,2,3]array2=[4,5,6]array_sum=array1+array2endputs please_work(array_sum)i ended up fiddling around and getting it to output [1,2,3,4,5,6], butmy syntex said i did not have the correct number of arguments. Also,sometimes i get array_sum is not a defined variable. If I am defining itin the method, shouldn't it be defined if i call the method again?thanks taking a look at my questionalex--Posted via http://www.ruby-forum.com/.--You received this message because you are subscribed to the Google Groups"Ruby on Rails: Talk" group.To unsubscribe from this group and stop receiving emails from it, send anTo post to this group, send email to rubyonrails-talk@googlegroups.com.To view this discussion on the web visithttps://groups.google.com/d/msgid/rubyonrails-talk/bc0aa129b0271b8f7159b64b5d0f6fd8%40ruby-forum.com.For more options, visit https://groups.google.com/groups/opt_out.--You received this message because you are subscribed to the Google Groups"Ruby on Rails: Talk" group.To unsubscribe from this group and stop receiving emails from it, send anTo post to this group, send email to rubyonrails-talk@googlegroups.com.To view this discussion on the web visitFor more options, visit https://groups.google.com/groups/opt_out.--You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.To post to this group, send email to rubyonrails-talk@googlegroups.com.To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtonPh-Jfah598uFUHXbtMWTMqmFY3JsRhjqzUGnE-kKg%40mail.gmail.com.For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/B4B4251B48AB4C1CB48A6FA89BE382CE%40gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment