Class: RDoc::Alias
- Inherits:
-
CodeObject
- Object
- CodeObject
- RDoc::Alias
- Defined in:
- lib/rdoc/alias.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
Text::MARKUP_FORMAT, Text::SPACE_SEPARATED_LETTER_CLASS, Text::TO_HTML_CHARACTERS
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, #parent, #received_nodoc, #section, #store, #viewer
Attributes included from Text
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 inherited from CodeObject
#display?, #documented?, #each_parent, #file_name, #full_name=, #ignore, #ignored?, #initialize_visibility, #options, #parent_file_name, #parent_name, #record_location, #start_doc, #stop_doc, #suppress, #suppressed?
Methods included from Generator::Markup
#aref_to, #as_href, #cvs_url, #description, #formatter
Methods included from Text
encode_fallback, #expand_tabs, #flush_left, #markup, #normalize_comment, #parse, #snippet, #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.
37 38 39 40 41 42 43 44 45 |
# File 'lib/rdoc/alias.rb', line 37 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
14 15 16 |
# File 'lib/rdoc/alias.rb', line 14 def new_name @new_name end |
#old_name ⇒ Object (readonly)
Aliasee method’s name
21 22 23 |
# File 'lib/rdoc/alias.rb', line 21 def old_name @old_name end |
#singleton ⇒ Object
Is this an alias declared in a singleton context?
26 27 28 |
# File 'lib/rdoc/alias.rb', line 26 def singleton @singleton end |
#text ⇒ Object (readonly)
Source file token stream
31 32 33 |
# File 'lib/rdoc/alias.rb', line 31 def text @text end |
Instance Method Details
#<=>(other) ⇒ Object
Order by #singleton then #new_name
50 51 52 |
# File 'lib/rdoc/alias.rb', line 50 def <=>(other) [@singleton ? 0 : 1, new_name] <=> [other.singleton ? 0 : 1, other.new_name] end |
#aref ⇒ Object
HTML fragment reference for this alias
57 58 59 60 |
# File 'lib/rdoc/alias.rb', line 57 def aref type = singleton ? 'c' : 'i' "#alias-#{type}-#{html_name}" end |
#full_old_name ⇒ Object
Full old name including namespace
65 66 67 |
# File 'lib/rdoc/alias.rb', line 65 def full_old_name @full_name || "#{parent.name}#{pretty_old_name}" end |
#html_name ⇒ Object
HTML id-friendly version of #new_name
.
72 73 74 |
# File 'lib/rdoc/alias.rb', line 72 def html_name CGI.escape(@new_name.gsub('-', '-2D')).gsub('%','-').sub(/^-/, '') end |
#inspect ⇒ Object
:nodoc:
76 77 78 79 80 81 82 |
# File 'lib/rdoc/alias.rb', line 76 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.
87 88 89 |
# File 'lib/rdoc/alias.rb', line 87 def name_prefix singleton ? '::' : '#' end |
#pretty_new_name ⇒ Object Also known as: pretty_name
New name with prefix ‘::’ or ‘#’.
101 102 103 |
# File 'lib/rdoc/alias.rb', line 101 def pretty_new_name "#{singleton ? '::' : '#'}#{@new_name}" end |
#pretty_old_name ⇒ Object
Old name with prefix ‘::’ or ‘#’.
94 95 96 |
# File 'lib/rdoc/alias.rb', line 94 def pretty_old_name "#{singleton ? '::' : '#'}#{@old_name}" end |
#to_s ⇒ Object
:nodoc:
107 108 109 |
# File 'lib/rdoc/alias.rb', line 107 def to_s # :nodoc: "alias: #{self.new_name} -> #{self.pretty_old_name} in: #{parent}" end |