以下の内容はhttps://tbpgr.hatenablog.com/entry/20140316/1394947331より取得しました。


ActiveSupport | Array options extraction

概要

Array options extraction

詳細

Array options extraction について

Array#options extraction

配列引数の最後のHashを抽出するArray#extract_options!メソッド
Arrayの最後のHashを返却する。最後の要素がHashでなければ空のHashを返却する。

サンプル

# encoding: utf-8
require 'active_support/core_ext/array/extract_options'
require 'tbpgr_utils'

I18n.enforce_available_locales = true
bulk_puts_eval binding, <<-EOS
[1,2,3, hoge: 'hoge', hige: 'hige'].extract_options!
[1,2,3, {hoge: 'hoge', hige: 'hige'}].extract_options!
[1,2,3].extract_options!
EOS

__END__
・下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils

出力

[1,2,3, hoge: 'hoge', hige: 'hige'].extract_options! # => {:hoge=>"hoge", :hige=>"hige"}
[1,2,3, {hoge: 'hoge', hige: 'hige'}].extract_options! # => {:hoge=>"hoge", :hige=>"hige"}
[1,2,3].extract_options! # => {}



以上の内容はhttps://tbpgr.hatenablog.com/entry/20140316/1394947331より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14