码迷,mamicode.com
首页 > 其他好文 > 详细

<Ruby> Basics

时间:2016-09-06 00:56:03      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:

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

<Ruby> Basics

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!