We contain the common stuff for contexts (which are containers) and other elements (methods, attributes and so on)
There’s a wee trick we pull. Comment blocks can have directives that override the stuff we extract during the parse. So, we have a special class method, ::attr_overridable, that lets code objects list those directives. Wehn a comment is assigned, we then extract out any matching directives and update our object
# File rdoc/code_objects.rb, line 104
def self.attr_overridable(name, *aliases)
@overridables ||= {}
attr_accessor name
aliases.unshift name
aliases.each do |directive_name|
@overridables[directive_name.to_s] = name
end
end
Update the comment, but don’t overwrite a real comment with an empty one
# File rdoc/code_objects.rb, line 94
def comment=(comment)
@comment = comment unless comment.empty?
end
# File rdoc/code_objects.rb, line 64
def document_children=(val)
@document_children = val
if !val
remove_classes_and_modules
end
end
# File rdoc/code_objects.rb, line 41
def document_self=(val)
@document_self = val
if !val
remove_methods_etc
end
end
# File rdoc/code_objects.rb, line 74
def parent_file_name
@parent ? @parent.file_base_name : '(unknown)'
end
# File rdoc/code_objects.rb, line 78
def parent_name
@parent ? @parent.name : '(unknown)'
end
Default callbacks to nothing, but this is overridden for classes and modules
# File rdoc/code_objects.rb, line 84
def remove_classes_and_modules
end
# File rdoc/code_objects.rb, line 87
def remove_methods_etc
end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please see Improve the docs, or visit Documenting-ruby.org.
Access the code object’s comment