1
1

More than 3 years have passed since last update.

if文を簡単に

Posted at

if文をワンライナーで書くには?

str = "is this a book?"
if str.include?("?")
puts "yes, it is."
end

str = "is this a book?"
puts "yes, it is." if str.include("?")

学んだこと
・オブジェクト名.include?("文字列"とか配列)
・include?は正規表現は使えないっぽい
・三項演算子というものもある

1
1
0

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
1