Ruby
puts (1..10).to_a # 印出 1 ~ 10
puts (1...10).to_a # 印出 1 ~ 9
(1..10) # 範圍 1 ~ 10
('a'..'z') # 範圍 a ~ z
('A'..'Z') # 範圍 A ~ Z
# Loop
for i in 1..10
puts i
end
# case..when
age = 10
case age
when 0..3
puts "嬰兒"
when 4..10
puts "兒童"
when 11..17
puts "青少年"
else
puts "成年"
end
# 印出 1 ~ 100 之間所有的單數
p (1..100).select { |x| x x % 2 == 1 }
p (1..100).select { |x| x.odd? }
# 計算 1 ~ 100 的總和
p (1..100).reduce { |sum, x| sum + x }
p (1..100).sum
# 印出 5 個小於 100 且不重複的亂數
p (1...100).to_a.shuffle.first(5)
p (1...100).to_a.sample(5)
Familiarity with Rakuten Travel QA Workflow (Hands-On Experience)
Dec 4, 2024A compilation of essential vocabulary gathered during my internship at Rakuten, with a sum of 94.
Mar 21, 2024在 Ruby 裡,幾乎什麼東西都是物件
Mar 1, 2024create web applications in Ruby
Mar 1, 2024or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up