Method: MethodSource::MethodExtensions#class_comment

Defined in:
lib/method_source.rb

#class_commentString Also known as: module_comment

Return the comments associated with the method class/module.

Examples:

MethodSource::MethodExtensions.method(:included).module_comment
=>
   # This module is to be included by `Method` and `UnboundMethod` and
   # provides the `#source` functionality

Returns:

  • (String)

    The method's comments as a string

Raises:

  • SourceNotFoundException



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/method_source.rb', line 139

def class_comment
  if self.respond_to?(:receiver)
    class_inst_or_module =  self.receiver
  elsif self.respond_to?(:owner)
    class_inst_or_module = self.owner
  else
    return comment
  end

  if class_inst_or_module.respond_to?(:name)
    const_name = class_inst_or_module.name
  else
    const_name = class_inst_or_module.class.name
    class_inst_or_module = class_inst_or_module.class
  end

  location = class_inst_or_module.const_source_location(const_name)

  MethodSource.comment_helper(location, defined?(name) ? name : inspect)
end