OneBite.Dev - Coding blog in a bite size

declare a function with single parameter in Ruby

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

def add (num1)
  num1 + 1
end

This code declares a function called ‘add’ with a single parameter named ‘num1’. The function adds ‘1’ to the value of the parameter and then returns it. In other words, the function adds ‘1’ to the given number. To call this function, one would need to pass in a number as an argument, like ‘add(1)‘. The function would then return ‘2’.

ruby