Tbpgr Blog

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

ActiveSupport

ActiveSupport | Date calculations

概要 Date calculations 詳細 Date calculations について Date calculations 日付の操作に関する各種メソッドを提供します。 サンプル # encoding: utf-8 require 'active_support/core_ext/date/calculations' require 'tbpgr_utils' date = Date.new(2014…

ActiveSupport | Range#range_overlaps?

概要 Range#range_overlaps? 詳細 Range#range_overlaps? について Range#range_overlaps? メソッドの範囲が重なっているかどうかを返却する サンプル # encoding: utf-8 require 'active_support/core_ext/range/overlaps' require 'tbpgr_utils' bulk_puts…

ActiveSupport | Range#include?

概要 Range#include? 詳細 Range#include? について Range#include? 引数が範囲に含まれているか確認する サンプル # encoding: utf-8 require 'active_support/core_ext/range/include_range' require 'tbpgr_utils' bulk_puts_eval binding, <<-EOS (1..5)…

ActiveSupport | Range#to_s

概要 Range#to_s 詳細 Range#to_s について Range#to_s 範囲を文字列にする サンプル # encoding: utf-8 require 'active_support/core_ext/hash/keys' require 'tbpgr_utils' hash = { :key1 => :value1, :key2 => :value2, :key3 => :value3, "key4" => :v…

ActiveSupport | Hash#stringify_keys

概要 Hash#stringify_keys 詳細 Hash#stringify_keys について Hash#stringify_keys キーを文字列にする サンプル # encoding: utf-8 require 'active_support/core_ext/hash/stringify_keys' require 'tbpgr_utils' hash = { :key1 => :value1, :key2 => :v…

ActiveSupport | Hash#to_xml

概要 Hash#to_xml 詳細 Hash#to_xml について Hash#to_xml Hashをxmlに変換する。 サンプル # encoding: utf-8 require 'active_support/core_ext/hash/conversions' require 'tbpgr_utils' I18n.enforce_available_locales = true hash = { :key1 => :value…

ActiveSupport | Array#split

概要 Array#split 詳細 Array#split について Array#split 文字列のsplitの配列版 サンプル # encoding: utf-8 require 'active_support/core_ext/array/grouping' require 'tbpgr_utils' I18n.enforce_available_locales = true ary = [2, 1, 3, 1, 4] bulk…

ActiveSupport | Array#in_groups

概要 Array#in_groups 詳細 Array#in_groups について Array#in_groups 引数で指定した要素数の配列に分割します。 サンプル # encoding: utf-8 require 'active_support/core_ext/array/grouping' require 'tbpgr_utils' I18n.enforce_available_locales = …

ActiveSupport | Array#in_groups_of

概要 Array#in_groups_of 詳細 Array#in_groups_of について Array#in_groups_of 第一引数に指定した要素数ごとで配列を分割します。 デフォルトでは、余った要素はnilになります。 第二引数を指定した場合、余った要素に指定した値が設定されます。 サンプ…

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…