summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/method_source.rb24
-rw-r--r--lib/method_source/version.rb2
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/method_source.rb b/lib/method_source.rb
index 82cf947..92b3522 100644
--- a/lib/method_source.rb
+++ b/lib/method_source.rb
@@ -91,6 +91,30 @@ module MethodSource
# This module is to be included by `Method` and `UnboundMethod` and
# provides the `#source` functionality
module MethodExtensions
+
+ # 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).
+ # @param [Class] klass The class that includes the module.
+ 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
# Return the sourcecode for the method as a string
# (This functionality is only supported in Ruby 1.9 and above)
diff --git a/lib/method_source/version.rb b/lib/method_source/version.rb
index 38d90e1..05234be 100644
--- a/lib/method_source/version.rb
+++ b/lib/method_source/version.rb
@@ -1,3 +1,3 @@
module MethodSource
- VERSION = "0.3.4"
+ VERSION = "0.3.5"
end