Methods
Public Instance methods
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
# File lib/facets/core/symbol/camelcase.rb, line 17
  def camelcase( *args )
    self.to_s.camelcase( *args ).to_sym
  end
camelize( *args )
# File lib/facets/core/symbol/camelize.rb, line 6
  def camelize( *args )
    self.to_s.camelize( *args ).to_sym
  end
capitalize()
# File lib/facets/core/symbol/capitalize.rb, line 6
  def capitalize
    to_s.capitalize.to_sym
  end
capitalized?()
# File lib/facets/core/symbol/capitalized.rb, line 7
  def capitalized?
    to_s.capitalized?
  end
downcase()
# File lib/facets/core/symbol/downcase.rb, line 6
  def downcase
    to_s.downcase.to_sym
  end
downcase?()
# File lib/facets/core/symbol/downcase.rb, line 10
  def downcase?
    to_s.downcase?
  end
not?()
# File lib/facets/core/symbol/not.rb, line 4
  def not?
    self.to_s.slice(0,1) == '~'
  end
pad(i=1)

Easily manipulate undercores on symbols.

  :a.pad(2)         #=> :__a__
  :__a__.pad(-1)    #=> :_a_
# File lib/facets/core/symbol/pad.rb, line 9
  def pad(i=1)
    return self if i == 0
    s = self.to_s
    if i > 0
      return ( ('_'*i) + self.to_s + ('_'*i) ).to_sym
    else
      i *= -1
      return s[i..-i-1].to_sym if s[0..i-1] == ('_'*i) and s[-i..-1] == ('_'*i)
      return self
    end
  end
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
# File lib/facets/core/symbol/succ.rb, line 14
  def succ
    self.to_s.succ.intern
  end
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.

# File lib/facets/core/symbol/to_const.rb, line 13
  def to_const
    to_s.to_const
  end
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
# File lib/facets/core/symbol/to_proc.rb, line 21
  def to_proc
    Proc.new{|*args| args.shift.__send__(self, *args)}
  end
to_str()

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

# File lib/facets/core/symbol/to_str.rb, line 11
  def to_str
    String( self )
  end
underscore()
# File lib/facets/core/symbol/underscore.rb, line 6
  def underscore
    self.to_s.underscore.to_sym
  end
upcase()
# File lib/facets/core/symbol/upcase.rb, line 6
  def upcase
    to_s.upcase.to_sym
  end
upcase?()
# File lib/facets/core/symbol/upcase.rb, line 10
  def upcase?
    to_s.upcase?
  end
~()
# File lib/facets/core/symbol/not.rb, line 8
  def ~@
    if self.to_s.slice(0,1) == '~'
      "#{self.to_s[1..-1]}".to_sym
    else
      "~#{self}".to_sym
    end
  end