Create a new file named
Place the following code inside the file:
def hello_world puts "Hello world!" end hello_world() # or just 'hello_world' (without parenthesis)
Now, from a command line, execute the following:
The output should be:
defis a keyword that tells us that we're
def-ining a method - in this case,
hello_worldis the name of our method.
puts "Hello world!"
puts(or pipes to the console) the string
endis a keyword that signifies we're ending our definition of the
hello_worldmethod doesn't accept any arguments, you can omit the parenthesis by invoking the method