LoginSignup
1
2

More than 1 year has passed since last update.

Ruby初心者さんたちが抱くややこしさ

Last updated at Posted at 2022-04-07

初心者目線で書いています。
プロには違うと思うかも…

rubyのややこしさ①
いくつもほぼ同じことをするコードがある

出力するprint系コード
print("hello world")
#これは良い

printf("hello world")
#まだ大丈夫

puts "hello world"
#うーん…ギリギリ良いかな…?

p "hello world"
#うん、いらない

rubyややこしさ②
繰り返しコードの多さ

繰り返し
for i in 1..10 do
    print("hello")
end
#大丈夫、全然普通

while 1 < 5 do
    print("hello")
    i = i + 1
end
#forとwhileは全然問題ない

x = 3
until x <= 0 do
    print(x,"\n")
    x = x-1
end
#はぁ…まぁ良いけどさぁ

x = 1..10
x.each do
    print("hello!","\n")
end
#うーん…需要はあるか…

5.upto(10) do
    print("hello! ") # 6回繰り返された。
end
#使うのか?
10.downto(5) do
    print("hello! ") # 6回繰り返された
end
#いやdownもあるんかいΣ(゜o゜

10.times do
    print("hello! ")
end
#いやいらないかも

2.4.step(5.4,0.2) do
    print("hello!","\n")
end
#これはまぁまぁ需要あるかな?

もうお腹いっぱいです。
うーんややこしいw

これを覚えてることが不思議

1
2
7

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2