How to return more than one value from a function?


  In an action in admin_controller, I called a method in the model ci.rb
  The code is shown below:

   In controller:
       can_delete = Ci.is_ci_class_in_use(ci_type, @ci_classes)

   Then in model:

     class Ci < ActiveRecord::Base

       def self.is_ci_class_in_use(ci_type,ci_classes)
         for ci in @cis
           for ci_class in ci_classes
             if ci.content.ci_class.to_i ==
               can_delete = 0
               ci_number = ci.ci_number
               can_delete = 1
           break if can_delete==0
          break if can_delete==0
        return # I have to return two variables can_delete and
ci_number here.

     How can I return the two variables can_delete and ci_number?
     Please help.


Unnikrishnan Kp wrote:

Why dont you return it as an Array? - return [can_delete,ci_number]

On Jun 24, 11:09 am, Suneeta Km <>


Thank you for your help. I tried returning it as an array. Then I
printed it in the console to see how it is returned.

  can_delete = Ci.is_ci_class_in_use(ci_type, @ci_classes)
  puts "the value returned is: " +can_delete.to_s

It printed:
  the value returned is: 0CI15

  The value of can_delete = 0 and ci_number = CI15

How can I retrieve these values from the returned array?


return as hash or array
return {:can_delete => 0, :ci_number => what_ever_the_number}


thank you.. it works. I returned it as an array

Suneeta Km wrote:

thank you.. it works. I returned it as an array

You can also just use more than one variable on the receiving end and
send each value back independently (not in an array).

var_1, var_2 = some_method

def some_method
    return 'hi', 'there'