Calling another method in the same controller

Hi, probably this is realy simple, but for some reason i don’t see it.
probably i still don’t think object orriented :slight_smile:

lets say i have a piece of code which generates an array based on a few

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

class MyController < ApplicationController

def array_generator(length)
# Add whatever you want to your array here

def mymethod
array1 = array_generator(12)
array2 = array_generator(3)
array3 = array_generator(4)

puts array1.size #
puts array2.size #
puts array3.size #