<Ruby> Basics

时间:2016-09-06 00:54:40   收藏:0   阅读:204

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.)

原文:http://www.cnblogs.com/mjust/p/5844086.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!