Class Symbol
In: lib/facet/symbol/camelcase.rb
lib/facet/symbol/to_proc.rb
lib/facet/symbol/not%3F.rb
lib/facet/symbol/succ.rb
lib/facet/symbol/gen.rb
lib/facet/symbol/%7E.rb
lib/facet/symbol/pad.rb
lib/facet/symbol/to_const.rb
lib/facet/symbol/to_str.rb
Parent: Object

Methods

camelCase   camelcase   gen   not?   pad   succ   to_const   to_proc   to_str   ~  

Public Instance methods

camelCase(first=false, on='_\s')

Alias for camelcase

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 string.

  require 'facet/string/camelcase'

  "this_is a test".camelCase              #=> "ThisIsATest"
  "this_is a test".camelCase(false)       #=> "thisIsATest"
  "this_is a test".camelCase(false, ' ')  #=> "This_isATest"

Generates a new symbol that is unique among the method names of a given class or object. If no parameter is given then Object class is assumed.

  require 'facet/symbol/gen'

  :class.gen => :clast

Easily manipulate undercores on symbols.

  require 'facet/symbol/pad'

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

Successor method for symobol. This simply converts the symbol to a string uses String#succ and then converts it back to a symbol.

  require 'facet/symbol/succ'

  :a.succ => :b

Get a constant by a given symbol name.

  require 'facet/symbol/to_const'

  :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.

Turn a symbol into a proc calling the method to which it refers.

  require 'facet/symbol/to_proc'

  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

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

[Validate]