OneBite.Dev - Coding blog in a bite size

declare a function with multiple parameter in Ruby

Code snippet on how to declare a function with multiple parameter in Ruby

  def function_name(parameter_1, parameter_2, parameter_3)
    # Code
  end

This code is an example of how to declare a function with three parameters in Ruby. The first line of the code defines the start of a function and its name. After that, three parameters are listed inside the parentheses, separated by a comma. We can see that this function has three parameters, but you can use any number of parameters you need for your function. Finally, a line is left for you to add your code. The function is finished with the keyword “end”. Now, Ruby knows that whenever you call the function, it should run the code you put in the function with any parameters you put in.

ruby