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
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