method_introspection

This is a simplified variant of showing comments and source code.

It is based on John Mair's (banisterfiend) gem called method_source.

That gem is perfectly fine - however had, I found that I only required MRI support for my own gems since that is what I am using, so the code for other platforms was removed. Please refer to the original gem if you need support for these platforms - this here is mostly a stripped down variant.

I have also changed the code a bit more to my personal style to make it easier to work with.

Credit where credit is due - in this case the initial work was done on the gem method_source.

The license is thus the MIT license, as specified in the original variant of the gem "method_source", which is retained here. Please refer to that gem called method_source for a description of that gem.

The aim of method_introspection is similar but not as big in scope - it's essentially just a stripped down variant essentially and allows us to inspect ruby methods at runtime.

Introspect ruby methods at runtime

Method comments can be obtained via the comment method.

This library is written in pure Ruby.

Examples: display method source

Set.instance_method(:merge).source.display
# =>
def merge(enum)
  if enum.instance_of?(self.class)
    @hash.update(enum.instance_variable_get(:@hash))
  else
    do_with_enum(enum) { |o| add(o) }
  end

  self
end

Example: display method comments

Set.instance_method(:merge).comment.display
# =>
# Merges the elements of the given enumerable object to the set and
# returns self.