Comments are non executable code which describes the programming code.
Click on execute to see its output
Like Perl, Bash, and C Shell, Ruby uses the hash symbol (also called Pound Sign, number sign, Square, or octothorpe) for comments. Everything from the hash to the end of the line is ignored when the program is run by Ruby. For example, here's our
hello-world.rb program with comments.# My first Ruby program # On my way to Ruby fame & fortune! puts 'Hello world'
click on execute to see its output
You can append a comment to the end of a line of code, as well. Everything before the hash is treated as normal Ruby code.
puts 'Hello world' # Print out "Hello world"
Click on execute to see its output, change the code to try different output/text
You can also comment several lines at a time:
=begin This program will print "Hello world". =end puts 'Hello world'
Click on execute to see its output
No comments:
Post a Comment