summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn Mair <jrmair@gmail.com>2011-03-05 00:49:23 +1300
committerJohn Mair <jrmair@gmail.com>2011-03-05 00:49:23 +1300
commit2475bb9273c102e5fd3bfe778ab792635ff43cda (patch)
tree0772e4114c469af2c5ae81ac7b159a6eda5618d4 /lib
parent48bae3f587ec86f1e1984264eea3ddba124b73cf (diff)
downloadmethod_source-2475bb9273c102e5fd3bfe778ab792635ff43cda.tar.gz
version 0.3.5, now has support to take advantage of Method#source on rubinius
Diffstat (limited to 'lib')
-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