Note that older version of ruby.
Ruby print variable.
The ruby print function is used to display output on the screen.
We can then print the element s value using puts.
Ruby runtime programming workflow interactive ruby our roadmap object oriented programming variables reusing variable names things on the right go first built in data types numbers strings true false and nil symbols arrays hashes.
The puts function also displays output.
Here s how it works.
The string or integer value to be printed is passed as an argument to this function.
Def numbers puts 123 end numbers nil.
You can also print all the gem specific variables configuration with the gem env command.
Note that print does not do the same.
However puts automatically inserts a newline at the end of the line being printed.
But it can show up if you try to puts a variable as the last line of a method and you re using the return value of that method.
If you want to access these environment variables from ruby there is a special object you can use.
Instance variables begin with commat.
Let s discover how it works.
For each element in the sharks array ruby assigns that element to the local variable shark.
This is like p but it prints big hashes arrays in a nicer way.
Using environment variables in ruby.
Note in ruby you can access value of any variable or constant by putting a hash character just before that variable or constant.
Ruby has yet another printing method.