module MethodSource::MethodExtensions
This module is to be included by `Method` and `UnboundMethod` and provides the `#source` functionality
Public Class Methods
included(klass)
click to toggle source
We use the included hook to patch #source on rubinius. We need to use the included hook as Rubinius defines a `source` on Method so including a module will have no effect (as it's higher up the MRO). @param [Class] klass The class that includes the module.
Calls superclass method
# File lib/method_source.rb, line 79 def self.included(klass) if klass.method_defined?(:source) && Object.const_defined?(:RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/ klass.class_eval do orig_source = instance_method(:source) define_method(:source) do begin super rescue orig_source.bind(self).call end end end end end
Public Instance Methods
comment()
click to toggle source
Return the comments associated with the method as a string. @return [String] The method's comments as a string @raise SourceNotFoundException
@example
Set.instance_method(:clear).comment.display => # Removes all elements and returns self.
# File lib/method_source.rb, line 121 def comment MethodSource.comment_helper(source_location, defined?(name) ? name : inspect) end
source()
click to toggle source
Return the sourcecode for the method as a string @return [String] The method sourcecode as a string @raise SourceNotFoundException
@example
Set.instance_method(:clear).source.display => def clear @hash.clear self end
# File lib/method_source.rb, line 109 def source MethodSource.source_helper(source_location, defined?(name) ? name : inspect) end