Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thanks for both answers.</p> <p>It seems I came out with an equivalent solution at last : <strong>the mutable container</strong>.</p> <p>I created a new class '<code>OutputParameter</code>' that contains (as <strong>attr_accessors</strong>) the parameters that I want to output from my method. Then I passed an instance of this class to my method.</p> <pre><code> class OutputParameters attr_accessor :order_id, pizza end class RestaurantController &lt; ApplicationController def pizza_to_deliver(pizza_name, output_parameters) # pizza to eat pizza = Pizza.where(:name =&gt; pizza_name).first # unknown pizza return false if pizza.nil? # first customer order about this pizza id_of_the_order = Orders.where(:pizza_id =&gt; pizza.id).first # Output values returned output_parameters.pizza = pizza output_parameters.order_id = id_of_the_order true end end my_pizza_name = 'margerita' my_output = OutputParameters.new my_restaurant = RestaurantController.new if my_restaurant.pizza_to_deliver(my_pizza_name, my_output) then puts "Pizza to deliver : #{my_output.order_id}" rex_dog.eat(my_output.pizza) end </code></pre> <hr> <p>The hash or array you suggested seems even a better idea as it is more adaptative : I wouldn't have to declare a class.</p> <p>I would just use the merge! method</p> <pre><code> class RestaurantController &lt; ApplicationController def pizza_to_deliver(pizza_name, output_hash) # pizza to eat pizza = Pizza.where(:name =&gt; pizza_name).first # unknown pizza return false if pizza.nil? # first customer order about this pizza id_of_the_order = Orders.where(:pizza_id =&gt; pizza.id).first # Output values returned output_hash.merge!({:pizza =&gt; pizza}) output_hash.merge!({:id_of_the_order =&gt; id_of_the_order}) true end end my_pizza_name = 'margerita' my_output_hash = {} my_restaurant = RestaurantController.new if my_restaurant.pizza_to_deliver(my_pizza_name, my_output_hash) then puts "Pizza to deliver : #{my_output_hash[:id_of_the_order]}" rex_dog.eat(my_output_hash[:pizza]) end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload