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

Methods

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

Public Class methods

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

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.

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

  :HELLO.as_s.chomp('O')  #=> :HELL

Symbol ends in `!`.

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

Useful extension for &:symbol which makes it possible to pass arguments for method in block

  ['abc','','','def','ghi'].tap(&:delete.(''))
  #=> ['abc','def','ghi']

  [1,2,3].map(&:to_s.(2))
  #=> ['1','10','11']

  ['abc','cdef','xy','z','wwww'].select(&:size.() == 4)
  #=> ['cdef', 'wwww']

  ['abc','aaA','AaA','z'].count(&:upcase.().succ == 'AAB')
  #=> 2

  [%w{1 2 3 4 5},%w{6 7 8 9}].map(&:join.().length)
  #=> [5,4]

CREDIT: Ilya Vorontsov, Nobuyoshi Nakada

Just like String#chomp.

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

CREDIT: Trans

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

  :a.dup!  #=> :a

Just like String#lchomp.

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

CREDIT: Trans

Does a symbol have a "not" sign?

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

CREDIT: Trans

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

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

Symbol ends in `?`.

  :a?.query? #=> true
  :a.query?  #=> false
reader?()

Alias for plain?

Symbol ends in `=`.

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

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?

Returns truew if the given block throws the symbol, otherwise false. Note that throw inside the block must be used in one-argument form.

@return [true,false]

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"
writer?()

Alias for setter?

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

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

CREDIT: Trans

[Validate]