Class: Rouge::Symbol
Constant Summary collapse
- LOOKUP =
The symbols for t/f/n are the Ruby objects themselves.
{ :true => true, :false => false, :nil => nil, }
- KNOWNS =
{ :/ => [nil, :/], :"./" => [nil, :"./"], :"rouge.core//" => [:"rouge.core", :/], :"rouge.core/./" => [:"rouge.core", :"./"] }
- CACHE =
{}
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#name_parts ⇒ Object
readonly
Returns the value of attribute name_parts.
-
#name_s ⇒ Object
readonly
Returns the value of attribute name_s.
-
#new_sym ⇒ Object
readonly
Returns the value of attribute new_sym.
-
#ns ⇒ Object
readonly
Returns the value of attribute ns.
-
#ns_s ⇒ Object
readonly
Returns the value of attribute ns_s.
Class Method Summary collapse
Instance Method Summary collapse
- #==(right) ⇒ Object
-
#initialize(sym) ⇒ Symbol
constructor
A new instance of Symbol.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #to_sym ⇒ Object
Methods included from Metadata
Constructor Details
#initialize(sym) ⇒ Symbol
Returns a new instance of Symbol.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rouge/symbol.rb', line 25 def initialize(sym) if r = KNOWNS[sym] @ns = r[0] @name = r[1] else str = sym.to_s solidus = str.rindex('/') if solidus @ns = str[0...solidus].intern @name = str[solidus + 1..-1].intern else @ns = nil @name = sym end end @ns_s = @ns.to_s unless @ns.nil? @name_s = @name.to_s # split(sep, 0) means a trailing '.' won't become an empty component. (0 # is default) Contrast with split(sep, -1). @name_parts = @name_s.length > 1 ? @name_s.split('.', 0).map(&:intern) : [@name] @new_sym = (@name_s[-1] == ?. and @name_s.length > 1) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/rouge/symbol.rb', line 7 def name @name end |
#name_parts ⇒ Object (readonly)
Returns the value of attribute name_parts.
7 8 9 |
# File 'lib/rouge/symbol.rb', line 7 def name_parts @name_parts end |
#name_s ⇒ Object (readonly)
Returns the value of attribute name_s.
7 8 9 |
# File 'lib/rouge/symbol.rb', line 7 def name_s @name_s end |
#new_sym ⇒ Object (readonly)
Returns the value of attribute new_sym.
7 8 9 |
# File 'lib/rouge/symbol.rb', line 7 def new_sym @new_sym end |
#ns ⇒ Object (readonly)
Returns the value of attribute ns.
7 8 9 |
# File 'lib/rouge/symbol.rb', line 7 def ns @ns end |
#ns_s ⇒ Object (readonly)
Returns the value of attribute ns_s.
7 8 9 |
# File 'lib/rouge/symbol.rb', line 7 def ns_s @ns_s end |
Class Method Details
Instance Method Details
#==(right) ⇒ Object
74 75 76 |
# File 'lib/rouge/symbol.rb', line 74 def ==(right) right.is_a?(Rouge::Symbol) and right.ns == @ns and right.name == @name end |
#inspect ⇒ Object
66 67 68 |
# File 'lib/rouge/symbol.rb', line 66 def inspect "Rouge::Symbol[#{to_sym.inspect}]" end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/rouge/symbol.rb', line 70 def to_s "#{@ns ? "#@ns/" : ""}#@name" end |
#to_sym ⇒ Object
62 63 64 |
# File 'lib/rouge/symbol.rb', line 62 def to_sym :"#{to_s}" end |