LoginSignup
0
0

Ruby 標準ライブラリのクラスとメソッドまとめ

Last updated at Posted at 2023-07-05

:cherries:学んだことを随時まとめてく:cherries:
間違っている点があれば是非教えていただきたいです

  • Date クラス(日付処理)
#現在の日付(年/月/日)を取得
today = Date.today             #.year/.month/.day
puts today #=> yyyy-mm-dd      #=>yyyy/=>mm/=>dd

#文字列を日付に変換
date_str = "xxxx-xx-xx"#文字列
date = Date.parse(date_str)
puts date #=> xxxx-xx-xx(日付オブジェクト)

#日付オブジェクトを指定したフォーマットの文字列に変換
date = Date.today
formatted_date = date.strftime("%Y-%m-%d")   #("%Y年%m月%d日")
puts formatted_date #=> "xxxx-xx-xx"                #=> "xxxx年xx月xx日"
  • Stringクラス(文字列処理)
#文字列の長さ(文字数)を取得
str.length または str.size
#文字列が空であるかどうかを判定
str.empty?
#文字列を大文字または小文字に変換
str.upcase または str.downcase
#正規表現にマッチする部分を指定した文字列で置換
str.gsub(pattern, replacement)
#指定した区切り文字で文字列を分割し、配列に格納
str.split(separator)
#文字列に別の文字列を結合
str.concat(other_str)
0
0
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
0
0