Generate a unique symbol.
Symbol.generate => :-1
If key is given the new symbol will be prefixed with it.
Symbol.generate(:foo) => :foo-1 TODO: Is the generated symbol format acceptable?
CREDIT: Trans
Does a symbol have a "not" sign?
"friend".to_sym.not? #=> false "~friend".to_sym.not? #=> true
CREDIT: Trans
Convert symbol to string, apply string method and convert back to symbol via a fluent interface.
:HELLO.re_s.downcase
Successor method for symobol. This simply converts the symbol to a string uses String#succ and then converts it back to a symbol.
:a.succ => :b
TODO: Make this work more like a simple character dial?
Turn a symbol into a proc calling the method to which it refers.
up = :upcase.to_proc up.call("hello") #=> HELLO
More useful is the fact that this allows & to be used to coerce Symbol into Proc.
%w{foo bar qux}.map(&:upcase) #=> ["FOO","BAR","QUX"] [1, 2, 3].inject(&:+) #=> 6
And other conveniences such as:
%{john terry fiona}.map(&:capitalize) # -> %{John Terry Fiona} sum = numbers.inject(&:+)
TODO: This will be deprecated as of Ruby 1.9, since it will become standard Ruby.
CREDIT: Florian Gross (orignal), Nobuhiro Imai (current)