Class | Symbol

In:

lib/facets/more/typecast.rb
lib/facets/more/cut.rb
lib/facets/core/symbol/capitalize.rb
lib/facets/core/symbol/camelcase.rb
lib/facets/core/symbol/succ.rb
lib/facets/core/symbol/not.rb
lib/facets/core/symbol/upcase.rb
lib/facets/core/symbol/downcase.rb
lib/facets/core/symbol/pad.rb
lib/facets/core/symbol/capitalized.rb
lib/facets/core/symbol/to_proc.rb
lib/facets/core/symbol/to_const.rb
lib/facets/core/symbol/camelize.rb
lib/facets/core/symbol/underscore.rb
lib/facets/core/symbol/to_str.rb
lib/facets/core/symbol/to_s.rb
lib/facets/core/symbol/chomp.rb
lib/facets/core/symbol/self/generate.rb

Parent: | Object

CHANGE transami@gmail.com - removed freeze from id2name

### Methods

< camelcase camelize capitalize capitalized? cast_from chomp downcase downcase? generate not? pad succ to_const to_proc to_s to_str underscore upcase upcase? ~

### Public Class methods

cast_from(object)
generate(suffix=nil)

Generate a unique symbol.

      Symbol.generate => :<1>

If `suffix` is given the new symbol will be suffixed with it.

      Symbol.generate(:this) => :<2>this

### Public Instance methods

<(cutclass)

alias :_op_lt_without_cuts :<

camelcase( *args )

Converts a symbol to camelcase. By default capitalization occurs on whitespace and underscores. By setting the first parameter to `true` the first character can also be captizlized. The second parameter can be assigned a valid Regualr Expression characeter set to determine which characters to match for capitalizing subsequent parts of the symbol.

      :this_is_a_test.camelcase              #=> :ThisIsATest
      :this_is_a_test.camelcase(false)       #=> :thisIsATest

camelize( *args )
capitalize()
capitalized?()
chomp(seperator=nil)

Just like String#chomp.

downcase()
downcase?()
not?()
pad(i=1)

Easily manipulate undercores on symbols.

      :a.pad(2)         #=> :__a__
      :__a__.pad(-1)    #=> :_a_

succ()

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

to_const()

Get a constant by a given symbol name.

      :Class.to_const   #=> Class

Note this method is not as verstile as it should be, since it can not access contants relative to the current execution context. But without a binding_of_caller that does not seem possible.

to_proc()

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

to_s()

Same functionality as before, just a touch more efficient.

to_str()

Symbol‘s really are just simplified strings. Thus to_str seems quite reasonable. This uses the Kernal#String method.

underscore()
upcase()
upcase?()
~()

[Validate]