1.
puts "Hello"
This write "Hello" to the screen with a new line tailed to.
print "Hello"
Just like puts, but without new line.
2.
"You know nothing".length
This output the string length.
"Jon Snow".reverse
"wonS noJ"
"OVERWATCH".downcase #---> "overwatch" "overwatch".upcase #---> "OVERWATCH"
Let‘s play Overwatch...
3.
# I‘m a single line comment! =begin Well, I am a multiple line COMMENT! =end
4.
variable_name = gets.chomp
gets is the Ruby method that gets input from the user. When getting input, Ruby automatically adds a blank line (or newline) after each bit of input; chomp removes that extra line. (Your program will work fine without chomp, but you‘ll get extra blank lines everywhere.)
gets
is the Ruby method that getsinput from the user. When getting input, Ruby automatically adds a blank line (or newline) after each bit of input; chomp
removes that extra line. (Your program will work fine withoutchomp
, but you‘ll get extra blank lines everywhere.)
时间: 2024-10-19 21:30:55