1 # frozen_string_literal: true
3 # Represent an alias, which is an old_name/new_name pair associated with a
6 # TODO implement Alias as a proxy to a method/attribute, inheriting from
9 class RDoc::Alias < RDoc::CodeObject
12 # Aliased method's name
19 # Aliasee method's name
24 # Is this an alias declared in a singleton context?
26 attr_accessor :singleton
29 # Source file token stream
34 # Creates a new Alias with a token stream of +text+ that aliases +old_name+
35 # to +new_name+, has +comment+ and is a +singleton+ context.
37 def initialize(text, old_name, new_name, comment, singleton = false)
41 @singleton = singleton
44 self.comment = comment
48 # Order by #singleton then #new_name
51 [@singleton ? 0 : 1, new_name] <=> [other.singleton ? 0 : 1, other.new_name]
55 # HTML fragment reference for this alias
58 type = singleton ? 'c' : 'i'
59 "#alias-#{type}-#{html_name}"
63 # Full old name including namespace
66 @full_name || "#{parent.name}#{pretty_old_name}"
70 # HTML id-friendly version of +#new_name+.
73 CGI.escape(@new_name.gsub('-', '-2D')).gsub('%','-').sub(/^-/, '')
77 parent_name = parent ? parent.name : '(unknown)'
78 "#<%s:0x%x %s.alias_method %s, %s>" % [
79 self.class, object_id,
80 parent_name, @old_name, @new_name,
85 # '::' for the alias of a singleton method/attribute, '#' for instance-level.
88 singleton ? '::' : '#'
92 # Old name with prefix '::' or '#'.
95 "#{singleton ? '::' : '#'}#{@old_name}"
99 # New name with prefix '::' or '#'.
102 "#{singleton ? '::' : '#'}#{@new_name}"
105 alias pretty_name pretty_new_name
108 "alias: #{self.new_name} -> #{self.pretty_old_name} in: #{parent}"