Method: MethodSource::MethodExtensions.included

Defined in:
lib/method_source.rb

.included(klass) ⇒ Object

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).

Parameters:

  • klass (Class)

    The class that includes the module.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/method_source.rb', line 84

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