こしごぇ(B)

旧:http://d.hatena.ne.jp/koshigoeb/

ActiveSupport で実装されてるメソッドを眺めた part 2

おまけ。

ActiveSupport::Inflector#acronym

略語の定義。

[1] 1.9.3-p327(main)> ActiveSupport::Inflector.inflections do |inflect|
[1] 1.9.3-p327(main)*   puts 'uri'.camelize
[1] 1.9.3-p327(main)*   inflect.acronym 'URI'
[1] 1.9.3-p327(main)*   puts 'uri'.camelize
[1] 1.9.3-p327(main)* end
Uri
URI
=> nil

Kernel.capture, Kernel.silence

キャプチャ。

[1] 1.9.3-p327(main)> stream = capture(:stdout) { puts 'hoge' }
=> "hoge\n"
[2] 1.9.3-p327(main)> puts stream
hoge
=> nil

Kernel.quietly

STDOUT, STDERR を握りつぶす。

[1] 1.9.3-p327(main)> quietly { system 'hostname' }
=> true

ActiveSupport::TimeWithZone#httpdate

RFC822 / RFC2822

[1] 1.9.3-p327(main)> Time.now.httpdate
=> "Fri, 08 Mar 2013 09:01:41 GMT"
[2] 1.9.3-p327(main)> Date.today.iso8601
=> "2013-03-08"