Ruby/Development/print

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Prints nil: the variable exists but is not assigned

a = 0.0 if false    # This assignment is never executed
print a             # Prints nil: the variable exists but is not assigned
print b             # NameError: no variable or method named b exists



print Statement

# puts statement goes to the next line after printing the contents
# print statement the cursor is positioned on the same line
 
puts "Hello World"
puts "Good Morning"
# The output of this code is:
# Hello World
# Good Morning
# Now let"s use the print statement and see what the output will be:
print "Hello World"
print "Good Morning"



print vs puts

9.downto(1) {|n| print n }   # No newline between numbers
puts " blastoff!"            # End with a newline