Class: RDoc::Alias
- Inherits:
-
CodeObject
- Object
- CodeObject
- RDoc::Alias
- Includes:
- Generator::Markup
- Defined in:
- lib/rdoc/alias.rb,
lib/rdoc/generator/markup.rb
Overview
Represent an alias, which is an old_name/new_name pair associated with a particular context -- TODO implement Alias as a proxy to a method/attribute, inheriting from
MethodAttr
Constant Summary
Constants included from Text
Instance Attribute Summary collapse
-
#new_name ⇒ Object
(also: #name)
readonly
Aliased method's name.
-
#old_name ⇒ Object
readonly
Aliasee method's name.
-
#singleton ⇒ Object
Is this an alias declared in a singleton context?.
-
#text ⇒ Object
readonly
Source file token stream.
Attributes inherited from CodeObject
#comment, #document_children, #document_self, #done_documenting, #file, #force_documentation, #line, #metadata, #offset, #parent, #received_nodoc, #section, #viewer
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Order by #singleton then #new_name.
-
#aref ⇒ Object
HTML fragment reference for this alias.
-
#full_old_name ⇒ Object
Full old name including namespace.
-
#html_name ⇒ Object
HTML id-friendly version of
#new_name
. -
#initialize(text, old_name, new_name, comment, singleton = false) ⇒ Alias
constructor
Creates a new Alias with a token stream of
text
that aliasesold_name
tonew_name
, hascomment
and is asingleton
context. -
#inspect ⇒ Object
:nodoc:.
-
#name_prefix ⇒ Object
'::' for the alias of a singleton method/attribute, '#' for instance-level.
-
#pretty_new_name ⇒ Object
(also: #pretty_name)
New name with prefix '::' or '#'.
-
#pretty_old_name ⇒ Object
Old name with prefix '::' or '#'.
-
#to_s ⇒ Object
:nodoc:.
Methods included from Generator::Markup
#aref_to, #as_href, #cvs_url, #description, #formatter
Methods inherited from CodeObject
#display?, #documented?, #each_parent, #file_name, #full_name=, #ignore, #ignored?, #parent_file_name, #parent_name, #record_location, #start_doc, #stop_doc
Methods included from Text
encode_fallback, #expand_tabs, #flush_left, #markup, #normalize_comment, #parse, #strip_hashes, #strip_newlines, #strip_stars, #to_html, #wrap
Constructor Details
#initialize(text, old_name, new_name, comment, singleton = false) ⇒ Alias
Creates a new Alias with a token stream of text
that aliases old_name
to new_name
, has comment
and is a singleton
context.
38 39 40 41 42 43 44 45 46 |
# File 'lib/rdoc/alias.rb', line 38 def initialize(text, old_name, new_name, comment, singleton = false) super() @text = text @singleton = singleton @old_name = old_name @new_name = new_name self.comment = comment end |
Instance Attribute Details
#new_name ⇒ Object (readonly) Also known as: name
Aliased method's name
15 16 17 |
# File 'lib/rdoc/alias.rb', line 15 def new_name @new_name end |
#old_name ⇒ Object (readonly)
Aliasee method's name
22 23 24 |
# File 'lib/rdoc/alias.rb', line 22 def old_name @old_name end |
#singleton ⇒ Object
Is this an alias declared in a singleton context?
27 28 29 |
# File 'lib/rdoc/alias.rb', line 27 def singleton @singleton end |
#text ⇒ Object (readonly)
Source file token stream
32 33 34 |
# File 'lib/rdoc/alias.rb', line 32 def text @text end |
Instance Method Details
#<=>(other) ⇒ Object
Order by #singleton then #new_name
51 52 53 |
# File 'lib/rdoc/alias.rb', line 51 def <=>(other) [@singleton ? 0 : 1, new_name] <=> [other.singleton ? 0 : 1, other.new_name] end |
#aref ⇒ Object
HTML fragment reference for this alias
58 59 60 61 |
# File 'lib/rdoc/alias.rb', line 58 def aref type = singleton ? 'c' : 'i' "#alias-#{type}-#{html_name}" end |
#full_old_name ⇒ Object
Full old name including namespace
66 67 68 |
# File 'lib/rdoc/alias.rb', line 66 def full_old_name @full_name || "#{parent.name}#{pretty_old_name}" end |
#html_name ⇒ Object
HTML id-friendly version of #new_name
.
73 74 75 |
# File 'lib/rdoc/alias.rb', line 73 def html_name CGI.escape(@new_name.gsub('-', '-2D')).gsub('%','-').sub(/^-/, '') end |
#inspect ⇒ Object
:nodoc:
77 78 79 80 81 82 83 |
# File 'lib/rdoc/alias.rb', line 77 def inspect # :nodoc: parent_name = parent ? parent.name : '(unknown)' "#<%s:0x%x %s.alias_method %s, %s>" % [ self.class, object_id, parent_name, @old_name, @new_name, ] end |
#name_prefix ⇒ Object
'::' for the alias of a singleton method/attribute, '#' for instance-level.
88 89 90 |
# File 'lib/rdoc/alias.rb', line 88 def name_prefix singleton ? '::' : '#' end |
#pretty_new_name ⇒ Object Also known as: pretty_name
New name with prefix '::' or '#'.
102 103 104 |
# File 'lib/rdoc/alias.rb', line 102 def pretty_new_name "#{singleton ? '::' : '#'}#{@new_name}" end |
#pretty_old_name ⇒ Object
Old name with prefix '::' or '#'.
95 96 97 |
# File 'lib/rdoc/alias.rb', line 95 def pretty_old_name "#{singleton ? '::' : '#'}#{@old_name}" end |
#to_s ⇒ Object
:nodoc:
108 109 110 |
# File 'lib/rdoc/alias.rb', line 108 def to_s # :nodoc: "alias: #{self.new_name} -> #{self.pretty_old_name} in: #{parent}" end |