On 7 February 2013 17:17, alexeymuranov (Alexey Muranov) wrote:
> In my opinion, it would be more useful to have a method that checks if a
> given string matches one of a symbols in a given set.  It is hard for me
> to think of a situation where one needs to know is a string matches any
> of the created symbols whatsoever. Similarly, instead of
> #to_existing_symbol, it seems to me useful to have a method that
> efficiently finds a symbol in a set by its string representation.

That would be a property of the set rather than of Symbol, and can easily
be achieved by constructing a Hash whose values are the Symbols in question
and keys are the .to_s of the values.  e.g.

    class SymbolSet
      def initialize
        @hash = {}
      end
      def <<(sym)
        @hash[sym.to_s] = sym
      end
      def defined?(s)
        @hash.has_key? s.to_s
      end
      def existing_sym(s)
        @hash[s.to_s] or raise "symbol :'#{s}' not defined in this set"
      end
    end

I believe the original feature request is more useful, because while it is
trivial to construct the above class (or an improved version) it is much
more difficult to manage membership, especially when you care about "the
set of all symbols", which is a legitimate concern in the case of the DOS
attack mentioned in the original request.  Since the set of all symbols is
already available to Symbol (as Symbol.all_symbols), that seems the logical
place to implement the feature, if at all.