declare a simple function in Ruby
Code snippet on how to declare a simple function in Ruby
def say_hello
puts "Hello World!"
end
This is an example of a simple function written in Ruby. The function is called “say_hello”. It begins with the keyword “def”, which stands for “define”, followed by the function’s name. Inside the function, there is a single line of code that prints the string “Hello World!” to the console. Finally, the function is closed with the keyword “end”.
When this code is run, the execution will begin at the line with the keyword “def”. It will then move forward, line by line, until it reaches the “end” keyword. At this point, the function will execute the single line of code inside, which is to print the string “Hello World!” to the console.