[#44904] [ruby-trunk - Bug #5688][Open] Solaris10 で spawn を繰り返すとメモリリークする — okkez _ <redmine@...>

14 messages 2011/11/29

[ruby-dev:44780] [ruby-trunk - Feature #5554][Open] A method that applies self to a Proc if self is a Symbol

From: Tsuyoshi Sawada <sawadatsuyoshi@...>
Date: 2011-11-02 18:51:47 UTC
List: ruby-dev #44780
Issue #5554 has been reported by Tsuyoshi Sawada.

----------------------------------------
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; pr.call(self) end
end



-- 
http://redmine.ruby-lang.org

In This Thread

Prev Next