婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Ruby語法筆記

Ruby語法筆記

熱門標簽:電銷機器人廠商代理 滴滴外呼系統(tǒng) 白銀外呼paas系統(tǒng) 百度地圖標注自定義圖片 湖州u友防封電銷卡 高德地圖標注客服 常德電銷平臺外呼系統(tǒng)軟件價格 地圖標注賺錢項目注冊 徐州網(wǎng)絡(luò)外呼系統(tǒng)哪個好

接受用戶輸入

first_name = gets.chomp

首字母大寫

first_name.capitalize!

字母變大寫

first_name.upcase!

字母變小寫

first_name.downcase!

多行輸出

print EOF
  # 多行輸出
EOF

注釋

# 我是注釋

變量獲取

#{first_name}

變量

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

if/else

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


class Classname
  def functionname(params)
    puts params
  end
end

class1 = Classname.new
class1.functionname('1')
unless
unless false
  print 'ok'
else
  print 'no'
end    

是否包含字符

print 'puts'

user_input = gets.chomp

user_input.downcase!

if user_input.include?"s"
  print 'has s'
end

替換字符

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

在字符串中輸出變量值

puts 'okok #{user_input}'

while

counter = 1

while counter  11
  puts counter
  counter = counter + 1
end

Until

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

+= 、 -= 、 *=、 /=
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 num
end  

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

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

Next

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

數(shù)組

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

The .each Iterator迭代器

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

# one way to loop
numbers.each { |item| puts item }

# another way to loop
numbers.each do |item|
 puts item
end

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

10.times { print 'ok'})

Looping with 'While'

num = 1

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

Looping with 'Until'

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

Loop the Loop with Loop

num = 0

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

The .split Method,

text.split(",")

puts "Text to search through: "
text = gets.chomp
puts "Word to redact"
redact = gets.chomp

words = text.split(" ")

words.each do |word|
  print word
end

您可能感興趣的文章:
  • Ruby的基礎(chǔ)語法入門學習教程
  • Ruby編程中的語法使用風格推薦
  • Ruby基礎(chǔ)語法初探
  • Ruby中一些基本語法知識點的羅列匯總
  • ruby聲明式語法的實現(xiàn)例子
  • Ruby的基本語法學習總結(jié)
  • ruby 學習筆記(1) 初識語法
  • Ruby的語法和語言特性總結(jié)

標簽:張家界 普洱 公主嶺 梧州 荊門 遼寧 永州 三沙

巨人網(wǎng)絡(luò)通訊聲明:本文標題《Ruby語法筆記》,本文關(guān)鍵詞  Ruby,語法,筆記,Ruby,語法,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Ruby語法筆記》相關(guān)的同類信息!
  • 本頁收集關(guān)于Ruby語法筆記的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 青川县| 宿松县| 都昌县| 株洲县| 霍邱县| 琼中| 固原市| 罗平县| 兴义市| 无为县| 古交市| 博乐市| 慈溪市| 贡觉县| 黑龙江省| 九龙坡区| 布尔津县| 汾阳市| 北流市| 高要市| 万载县| 永川市| 清丰县| 正安县| 绍兴市| 会昌县| 漳浦县| 周宁县| 郧西县| 平泉县| 汾阳市| 嵊州市| 望城县| 如皋市| 丽江市| 英吉沙县| 揭西县| 宁城县| 石首市| 石景山区| 通辽市|