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 1 year has passed since last update.

算用数字を漢数字にするメソッド

Last updated at Posted at 2021-11-12

英数字を漢数字に変換するメソッドの自作

例えば 2021年9月11日 にこのメソッドを使うと
ニ〇ニ一年九月一一日 になる

開発環境

ruby 2.6.5
Ruby on Rails 5.2.5

本題

ヘルパーメソッド内に

  def convert_kansuji(text)
    text.tr('0123456789', '〇一二三四五六七八九')
  end

こんなふうに定義してやる

View の中で

convert_kansuji(@worship.worship_day.strftime("%Y年%m月%d日"))

こんなふうにしてやると変換される

0
0
2

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?