From: Tsuyoshi Sawada Date: 2011-11-03T17:58:19+09:00 Subject: [ruby-dev:44787] [ruby-trunk - Feature #5554] A method that applies self to a Proc if self is a Symbol Issue #5554 has been updated by Tsuyoshi Sawada. 本当は、意図したのは、どのようなSymbolがあるか簡単には分からない場合、もしくは別のところで関連するメソッドが定義されていて、Symbolの一覧を複数の場所で更新しなければならなくなる場合で、例えば次のような場合です:     proc =>sym{some_method_chain.send(sym)} # sym can be :foo, :bar, ..., which are defined elsewhere でも、中田さんのおっしゃているのも分かります。 ---------------------------------------- Feature #5554: A method that applies self to a Proc if self is a Symbol http://redmine.ruby-lang.org/issues/5554 Author: Tsuyoshi Sawada Status: Open Priority: Normal Assignee: Category: Target version: Often, you want to apply a Proc to self if self is a Symbol, but not do anything if otherwise. In this case, something I call Object#desymbolize may be convenient: proc = ->sym{ case sym when :small_icon then "16pt" when :medium_icon then "32pt" when :large_icon then "64pt" end } :small_icon.desymbolize(&proc) => "16pt" "18pt".desymbolize(&proc) => "18pt" An implementation may be as follows: class Object def desymbolize; self end end class Symbol def desymbolize ≺ pr.call(self) end end -- http://redmine.ruby-lang.org