OneBite.Dev - Coding blog in a bite size

call a function with parameter in Ruby

Code snippet on how to call a function with parameter in Ruby

  def say_hello(name)
    puts "Hello #{name}"
  end
  
  say_hello("John")

This code is written in Ruby, and is calling a function that can say hello to a person. The code first defines a function called “say_hello” that takes one parameter, “name”. Then it uses the puts command to output the text “Hello” with the value of “name” after it. Finally, the code calls the function and passes in the string “John” as the parameter. This means that the code will output a line that says “Hello John”.

ruby