0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Boolean型からString型にする方法

Posted at

#問題
bにboolean型でtrueかfalseが与えられる時、string型に変更せよ。

def boolean_to_string(b)
  return
end

##解答1

def boolean_to_string(b)
  b ? "true" : "false"
end

三項演算子なるほど。

##解答2

def boolean_to_string(b)
  b.to_s
end

##解答3

def boolean_to_string(b)
  b.inspect
end

inspect使ったことないですができるんですね!

感想

Codewarsは他の人が書いたコードが読めるのですごく勉強になりますね!

0
0
1

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?