rubilicious

Learn Ruby the Hard Way

by Zed Shaw

Example 3

Previous   Next

The method puts method prints the string that follows to the screen and returns the cursor to the next line.

puts "I will now count my chickens:"

# the puts method print the string that follows to the screen and returns the cursor to the next line.
# Using the operator presedence; first the division operator divides 30 by 6 then adds the integers and prints them to the screen  puts "Hens", 25 + 30 / 6

# the puts method prints the string that follows to the screen and returns the cursor to the next line.
# Using the operator presedence; first the division operator divides 25 by 4 then subtracts and prints the result to the screen
puts "Roosters" , 100 - 25 % 4

# the puts method prints the string that follows to the screen and returns the cursor to the next line.
puts "Now I will count the eggs:"

# the puts method prints the result of the equation. The equation is solved using operator presedence.
puts  3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 +6

# the puts method prints the string that follows to the screen and returns the cursor to the next line.
puts "Let's look at Boolean values..."

# the puts method prints the string that follows to the screen and returns the cursor to the next line.
puts "Is it true that 3 + 2 < 5 - 7?"

# the puts method prints the result of the equation as a boolean (true or false) and returns the cursor to the next line. puts 3 + 2 < 5 - 7

# the puts method prints the string to the screen, returns the cursor to the next line and prints the result of the equation.
puts "What is 3 + 2?", 3 + 2

# the puts method prints the string to the screen, returns the cursor to the next line and prints the result of the equation.
puts "What is 5 - 7?" , 5 - 7

# the puts method prints the string that follows to the screen and returns the cursor to the next line.
puts "Oh, that's why it's false."

# the puts method prints the string that follows to the screen and returns the cursor to the next line.
puts "How about some more?"

# the puts method prints the string that follows to the screen, returns the cursor to the next line where the comparison operator makes it's deduction.
puts "Is it greater?" , 5.0 > -2.0

# the puts method prints the string that follows to the screen, returns the cursor to the next line where the comparison operator makes it's deduction.
puts "Is it greater or equal?", 5 >= -2

# the puts method prints the string that follows to the screen, returns the cursor to the next line where the comparison operator makes it's deduction.
puts "Is it less or equal?" , 5 <= -2

# the puts method prints the result of the division to the screen and returns the cursor to the next line
puts 38.0 / 6.0

# definitions...
puts "Addition - Adds values on either side of the operator"
puts "Subtraction - Subtracts right hand operand from the left hand operand"
puts "Multiplication - Multiplies values on either side of the operator"
puts "Division - Divides left hand operand by right hand operand"
puts "Modulus - Divides left hand operand by right hand operand and returns the remainder"
puts "Exponent - Performs exponential (power) calculation on operators"
puts "< <= > >= Comparison Operators"
puts "The assignment operator = assigns the result of an operation to a variable"