Hi, probably this is realy simple, but for some reason i don''t see it. probably i still don''t think object orriented :) lets say i have a piece of code which generates an array based on a few inputs. within a controller i want to use this code to generate three arrays, all based on different input variables how do i do that? can i call another method within a method? if so, how? hope somebody can explain it to me, i would be very gratefull regards -- Posted via http://www.ruby-forum.com/.
Christos Zisopoulos
2006-Jul-28 10:56 UTC
[Rails] Calling another method in the same controller
Yes, like in most languages you can call a method from another method. You have to be careful about access control though. Have a look at ''public'', ''private'', ''protected'' function calls used to control access to your methods from outside the controller. There is a short description in section 7.8 of http://www.rubycentral.com/faq/ rubyfaqall.html class MyController < ApplicationController def array_generator(length) Array.new(length) # Add whatever you want to your array here end def mymethod array1 = array_generator(12) array2 = array_generator(3) array3 = array_generator(4) puts array1.size # puts array2.size # puts array3.size # end end -christos On 26 Jul 2006, at 14:50, Remco wrote:> Hi, probably this is realy simple, but for some reason i don''t see it. > probably i still don''t think object orriented :) > > lets say i have a piece of code which generates an array based on a > few > inputs. > > within a controller i want to use this code to generate three arrays, > all based on different input variables how do i do that? > can i call another method within a method? if so, how? > > hope somebody can explain it to me, i would be very gratefull > > regards > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails