麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁(yè) > 編程 > Ruby > 正文

Ruby語(yǔ)法筆記

2020-10-29 19:36:37
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

接受用戶輸入

first_name = gets.chomp

首字母大寫(xiě)

first_name.capitalize!

字母變大寫(xiě)

first_name.upcase!

字母變小寫(xiě)

first_name.downcase!

多行輸出

print <<EOF  # 多行輸出EOF

注釋

# 我是注釋

變量獲取

#{first_name}

變量

  1. 全局變量 $
  2. 類變量 @@
  3. 方法變量 @
  4. 局部變量 小寫(xiě)字母或_

if/else

if a < b  puts '1'elsif b < a  puts '2'end    


class Classname  def functionname(params)    puts params  endendclass1 = Classname.newclass1.functionname('1')unlessunless false  print 'ok'else  print 'no'end    

是否包含字符

print 'puts'user_input = gets.chompuser_input.downcase!if user_input.include?"s"  print 'has s'end

替換字符

# s -> thuser_input.gsub!(/s/,"th")

在字符串中輸出變量值

puts 'okok #{user_input}'

while

counter = 1while counter < 11  puts counter  counter = counter + 1end

Until

counter = 1until counter > 10  print counter  counter = counter + 1end  

+= 、 -= 、 *=、 /=
Some languages have the increment operators ++ and -- (which also add or subtract 1 from a value), but Ruby does not
for循環(huán)
# 如果 1...10 包含1-9,如果 1..10 包含1-10

for num in 1...10  puts numend  

Loop Method
An iterator is just a Ruby method that repeatedly invokes a block of code.

i = 20loop do  i -= 1  print "#{ i }"  break if i <= 0end  

Next

i = 20loop do i -= 1 next if i%2 != 0 print "#{i}" break if i <= 0end

數(shù)組

my_array = [1,2,3,4,5]

The .each Iterator迭代器

numbers = [1, 2, 3, 4, 5]# one way to loopnumbers.each { |item| puts item }# another way to loopnumbers.each do |item| puts itemend

The .times Iterator 次數(shù)迭代器

10.times { print 'ok'})

Looping with 'While'

num = 1while num <= 50 do  print num  num += 1end  

Looping with 'Until'

num = 1until num > 50 do  print num  num += 1end  

Loop the Loop with Loop

num = 0loop do  num += 1  print "Ruby!"  break if num == 30end  

The .split Method,

text.split(",")puts "Text to search through: "text = gets.chompputs "Word to redact"redact = gets.chompwords = text.split(" ")words.each do |word|  print wordend

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 久久久久久久久久久国产精品 | 精品国产一区二区三区在线观看 | 亚洲片在线观看 | 亚洲国产一区二区三区 | 国产超碰人人爽人人做人人爱 | 免费看污视频在线观看 | 久久2019中文字幕 | 国产精品18久久久久久久久 | 欧美黑人伦理 | 天天透天天狠天天爱综合97 | 91短视频网页版 | 中国美女一级黄色大片 | 澳门一级淫片免费视频 | 国产做爰全免费的视频黑人 | 精品久久一区二区 | 成人在线观看免费视频 | 国产精品91在线 | 中文字幕国 | hd日本xxxx| 黄色网址在线视频 | 国产精品久久久久久久久久久久久久久久 | 久久最新网址 | 可以免费看的av | 欧美老外a级毛片 | 黄色网址在线播放 | 天堂成人一区二区三区 | 丁香天堂网 | 免费欧美精品 | 羞羞网站在线看 | 成人做爽爽爽爽免费国产软件 | 特级a欧美做爰片毛片 | 久久久久久久久久亚洲 | 久草成人在线观看 | 91福利国产在线观一区二区 | 久久精品中文字幕一区二区 | 在线日韩亚洲 | 国产日韩久久久久69影院 | 精品久久一区二区 | 欧美性生活区 | 欧美a∨亚洲欧美亚洲 | 激情综合网俺也去 |