Module: MethodSource::MethodExtensions
- Included in:
- Method, Proc, UnboundMethod
- Defined in:
- lib/method_source.rb
Overview
This module is to be included by Method and UnboundMethod and
provides the #source functionality
Class Method Summary (collapse)
-
+ (Object) included(klass)
We use the included hook to patch Method#source on rubinius.
Instance Method Summary (collapse)
-
- (String) comment
Return the comments associated with the method as a string.
-
- (String) source
Return the sourcecode for the method as a string (This functionality is only supported in Ruby 1.9 and above).
Class Method Details
+ (Object) included(klass)
We use the included hook to patch Method#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).
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/method_source.rb', line 87 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 |
Instance Method Details
- (String) comment
Return the comments associated with the method as a string. (This functionality is only supported in Ruby 1.9 and above)
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/method_source.rb', line 135 def comment if respond_to?(:source_location) comment = MethodSource.comment_helper(source_location) raise "Cannot locate source for this method: #{name}" if !comment else raise "#{self.class}#comment not supported by this Ruby version (#{RUBY_VERSION})" end comment end |
- (String) source
Return the sourcecode for the method as a string (This functionality is only supported in Ruby 1.9 and above)
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/method_source.rb', line 116 def source if respond_to?(:source_location) source = MethodSource.source_helper(source_location) raise "Cannot locate source for this method: #{name}" if !source else raise "#{self.class}#source not supported by this Ruby version (#{RUBY_VERSION})" end source end |