Class | Symbol
In: | lib/core/facets/object/dup.rb lib/core/facets/symbol/as_s.rb lib/core/facets/symbol/chomp.rb lib/core/facets/symbol/generate.rb lib/core/facets/symbol/not.rb lib/core/facets/symbol/op_div.rb lib/core/facets/symbol/plain.rb lib/core/facets/symbol/succ.rb lib/core/facets/symbol/thrown.rb lib/core/facets/symbol/to_proc.rb lib/core/facets/symbol/variablize.rb
Parent: | Object

### Methods

/ as_s bang? chomp clone? dup! dup? generate lchomp not? plain? query? setter? succ thrown? to_proc variablize ~

### Public Class methods

generate(key=nil)

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

### Public Instance methods

/(path)

Join with path as a file path.

- path - The path component(s) to append. [to_s]

Examples

      (:merb / "string")   #=> "merb/string"
      (:merb / :symbol)    #=> "merb/symbol"

Returns String of the receiver (as a path string), concatenated with path.

as_s()

Convert symbol to string, apply string method and convert back to symbol via a fluent interface.

      :HELLO.as_s.downcase  #=> :hello

bang?()

Symbol ends in `!`.

      :a!.bang? #=> true
      :a.bang?  #=> false

chomp(seperator)

Just like String#chomp.

      :ab.chomp(:b)  #=> :a

CREDIT: Trans

clone?()
dup!()

Since Symbol is immutable it cannot be duplicated. For this reason try_dup returns `self`.

      :a.dup!  #=> :a

dup?()
lchomp(seperator)

Just like String#lchomp.

      :ab.lchomp(:a)  #=> :b

CREDIT: Trans

not?()

Does a symbol have a "not" sign?

      "friend".to_sym.not?   #=> false
      "~friend".to_sym.not?  #=> true

CREDIT: Trans

plain?()

Symbol does not end in `!`, `=`, or `?`.

      :a.plain?   #=> true
      :a?.plain?  #=> false
      :a!.plain?  #=> false
      :a=.plain?  #=> false

query?()

Symbol ends in `?`.

      :a?.query? #=> true
      :a.query?  #=> false

setter?()

Symbol ends in `=`.

      :a=.setter? #=> true
      :a.setter?  #=> false

succ(n=1)

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?

thrown?() {|| ...}

Does the block throw the symbol?

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

TODO: This will be deprecated as of Ruby 1.9, since it will become standard Ruby.

CREDIT: Florian Gross (orignal), Nobuhiro Imai (current)

variablize()

Prepend an "@" to the beginning of a symbol to make a instance variable name. This also replaces non-valid characters with underscores.

      :a.variablize  #=> :"@a"

~()

Add a "not" sign to the front of a symbol.

      (~:friend)  #=> :"~friend"

CREDIT: Trans

[Validate]