From 2475bb9273c102e5fd3bfe778ab792635ff43cda Mon Sep 17 00:00:00 2001 From: John Mair Date: Sat, 5 Mar 2011 00:49:23 +1300 Subject: version 0.3.5, now has support to take advantage of Method#source on rubinius --- lib/method_source.rb | 24 ++++++++++++++++++++++++ lib/method_source/version.rb | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) (limited to 'lib') 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 -- cgit v1.2.1