Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby on Rails

ActiveSupport | Array.wrap

概要 Array.wrap 詳細 Array.wrap について Array.wrap 引数をラップして配列にする。 詳細はサンプル参照。 サンプル # encoding: utf-8 require 'active_support/core_ext/array/wrap' require 'tbpgr_utils' I18n.enforce_available_locales = true bulk_…

ActiveSupport | Array#to_xml

概要 Array#to_xml 詳細 Array#to_xml について Array#to_xml リストをxmlに変換する 詳細はサンプル参照。 サンプル # encoding: utf-8 require 'active_support/core_ext/array/conversions' puts %w!hoge!.to_xml puts [ { name: 'hoge', age: 23, }, { n…

ActiveSupport | Array#to_sentence

概要 Array#to_sentence 詳細 Array#to_sentence について Array#to_sentence リストを英文で単語を列挙する際のフォーマットにする。 詳細はサンプル参照。 サンプル # encoding: utf-8 require 'active_support/core_ext/array/conversions' require 'tbpg…

ActiveSupport | Array options extraction

概要 Array options extraction 詳細 Array options extraction について Array#options extraction 配列引数の最後のHashを抽出するArray#extract_options!メソッド。 Arrayの最後のHashを返却する。最後の要素がHashでなければ空のHashを返却する。 サンプ…

ActiveSupport | Array adding

概要 Array adding 詳細 Array adding について Array#adding 配列への要素追加のエイリアス。prepend(unshiftのエイリアス) と append(エイリアス) サンプル # encoding: utf-8 require 'active_support/core_ext/array/access' require 'tbpgr_utils' …

ActiveSupport | Array#accessing

概要 Array#accessing 詳細 Array#accessing について Array#accessing 配列の任意の位置にアクセスします。 サンプル # encoding: utf-8 require 'active_support/core_ext/array/access' require 'tbpgr_utils' I18n.enforce_available_locales = true ary…

ActiveSupport | Enumerable#exclude?

概要 Enumerable#exclude? 詳細 Enumerable#exclude? について Enumerable#exclude? include?の否定 サンプル # encoding: utf-8 require 'active_support/core_ext/enumerable' require 'tbpgr_utils' I18n.enforce_available_locales = true bulk_puts_eva…

ActiveSupport | Enumerable#many?

概要 Enumerable#many? 詳細 Enumerable#many? について Enumerable#many? size > 1 サンプル # encoding: utf-8 require 'active_support/core_ext/enumerable' require 'tbpgr_utils' I18n.enforce_available_locales = true bulk_puts_eval binding, <<-E…

ActiveSupport | Enumerable#sum

概要 Enumerable#sum 詳細 Enumerable#sum について Enumerable#sum 対象を合計した結果を返却します。 +演算子を利用しているため、文字列も連結します。 ブロックの指定も可能です。 空要素の場合はデフォルトでゼロを返却しますが、初期値を引数に渡すこ…

ActiveSupport | ordinalize

概要 ordinalize 詳細 ordinalize について ordinalize 数値を序数のサフィックス付きのフォーマットにします。 サンプル # encoding: utf-8 require 'active_support/core_ext/integer/inflections' require 'tbpgr_utils' I18n.enforce_available_locales …

ActiveSupport | ordinal

概要 ordinal 詳細 ordinal について ordinal 序数のサフィックスを取得します。 サンプル # encoding: utf-8 require 'active_support/core_ext/integer/inflections' require 'tbpgr_utils' bulk_puts_eval binding, <<-EOS 1.ordinal 2.ordinal 3.ordinal…

ActiveSupport | multiple_of?

概要 multiple_of? 詳細 multiple_of? について multiple_of? 数値が引数の数値の倍数であるか判定する サンプル # encoding: utf-8 require 'active_support/core_ext/integer/multiple' require 'tbpgr_utils' bulk_puts_eval binding, <<-EOS 1.multiple_…

ActiveSupport | formatting

概要 formatting 詳細 formatting について formatting 数値を任意のフォーマットに変更する フォーマット フォーマット phone currency percentage delimited rounded human_size human ※実際の出力内容はサンプルコード参照 操作 メソッド 内容 since 指定…

ActiveSupport | time

概要 time 詳細 time について time 数値を元にして日時を扱う。 単位 メソッド 内容 seconds 秒 minutes 分 hours 時 days 日 weeks 週 week 週(weeksのエイリアス) fortnights 2週間 months 月 years 年 ※補足 fortnight => 2週間の意 操作 メソッド …

ActiveSupport | bytes

概要 bytes 詳細 bytes について bytes 数値を単位ごとのバイト数に変換する。・bytes ・kilobytes ・megabytes ・gigabytes ・terabytes ・petabytes ・exabytes サンプル # encoding: utf-8 require 'active_support/core_ext/numeric/bytes' require 'tbp…

ActiveSupport | String#conversion

概要 String#conversion 詳細 String#conversion について String#conversion Date._parseを便利にしたラッパーのようなメソッド。 サンプル # encoding: utf-8 require 'active_support/core_ext/string/conversions' require 'tbpgr_utils' bulk_puts_eval…

ActiveSupport | String#foreign_key

概要 String#foreign_key 詳細 String#foreign_key について String#foreign_key 文字列から外部キー用の文字列を取得する。 サンプル # encoding: utf-8 require 'active_support/core_ext/string/inflections' require 'tbpgr_utils' bulk_puts_eval bindi…

ActiveSupport | String#humanize

概要 String#humanize 詳細 String#humanize について String#humanize 属性の名前を人が見やすい形式に変換する。 アンダースコアをスペースに変更し、 _idを削除し、 先頭の単語をCapitalizeします。 サンプル # encoding: utf-8 require 'active_support/…

ActiveSupport | String#constantize

概要 String#constantize 詳細 String#constantize について String#constantize 文字列から定数を取得する サンプル # encoding: utf-8 require 'active_support/core_ext/string/inflections' require 'tbpgr_utils' class Hoge HIGE = "hige" end bulk_pu…

ActiveSupport | String#classify

概要 String#classify 詳細 String#classify について String#classify 文字列をクラス名形式にする。 tableizeの反対。 サンプル # encoding: utf-8 require 'active_support/core_ext/string/inflections' require 'tbpgr_utils' bulk_puts_eval binding, <…

ActiveSupport | String#tableize

概要 String#tableize 詳細 String#tableize について String#tableize 文字列を複数形かつアンダースコア区切りに変更する。 underscoreとpluralizeの組み合わせ。 サンプル # encoding: utf-8 require 'active_support/core_ext/string/inflections' requi…

ActiveSupport | String#parameterize

概要 String#parameterize 詳細 String#parameterize について String#parameterize 指定文字列に含まれている[a-z0-9\-_]以外の文字を引数sepに置き換えます。 sepを指定しなかった場合は半角ハイフンになります。 サンプル # encoding: utf-8 require 'act…

ActiveSupport | String#demodulize

概要 String#demodulize 詳細 String#demodulize について String#demodulize モジュール::モジュール::任意の名称,などの文字列から右端の任意の名称を取得する。 サンプル # encoding: utf-8 require 'active_support/core_ext/string/inflections' requir…

ActiveSupport | String#dasherize

概要 String#dasherize 詳細 String#dasherize について String#dasherize 文字列をハイフン区切りにした結果を受け取る サンプル # encoding: utf-8 require 'active_support/core_ext/string/inflections' require 'tbpgr_utils' bulk_puts_eval binding, <…

ActiveSupport | String#titleize

概要 String#titleize 詳細 String#titleize について String#titleize 文字列を区切り文字ごとに先頭大文字にする。 サンプル # encoding: utf-8 require 'active_support/core_ext/string/inflections' require 'tbpgr_utils' bulk_puts_eval binding, <<-…

ActiveSupport | String#underscore

概要 String#underscore 詳細 String#underscore について String#underscore 文字列をスネークケースにした結果を受け取る サンプル # encoding: utf-8 require 'active_support/core_ext/string/inflections' require 'tbpgr_utils' bulk_puts_eval bindin…

ActiveSupport | String#camelize

概要 String#camelize 詳細 String#camelize について String#camelize 文字列をキャメルケースにした結果を受け取る 引数に「:lower」を与えると、最初の文字が小文字になる サンプル # encoding: utf-8 require 'active_support/core_ext/string/inflectio…

ActiveSupport | String#singularize

概要 String#singularize 詳細 String#singularize について String#singularize 文字列の単数形を返却する。 サンプル # encoding: utf-8 require 'active_support/core_ext/string/inflections' require 'tbpgr_utils' bulk_puts_eval binding, <<-EOS 'he…

ActiveSupport | String#pluralize

概要 String#pluralize 詳細 String#pluralize について String#pluralize 文字列の複数形を返却する。 plural は「複数」の意。引数に数値を与えた場合、1の場合は単数形。それ以外は複数形を返却します。 何かの結果サイズによって文言を変更したい時など…

オープンソース開発 | はじめてのPull Request。Rails GuidesにPull Requestを送ってみたら瞬殺でマージされた

概要 はじめてのPull Request。Rails GuidesにPull Requestを送ってみたら瞬殺でマージされた 経緯 最近、ライブラリを覚えるのとOSSのコードリーディングも兼ねてRailsのActiveSupportのGuideと GitHubのコードを毎日読んでいました。String#indentのGuide…