首页 > 代码库 > <Ruby> Basics

<Ruby> Basics

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!=beginWell,I am amultiple lineCOMMENT!=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.)

<Ruby> Basics