diff options
author | John Mair <jrmair@gmail.com> | 2011-03-05 00:49:23 +1300 |
---|---|---|
committer | John Mair <jrmair@gmail.com> | 2011-03-05 00:49:23 +1300 |
commit | 2475bb9273c102e5fd3bfe778ab792635ff43cda (patch) | |
tree | 0772e4114c469af2c5ae81ac7b159a6eda5618d4 /lib/method_source.rb | |
parent | 48bae3f587ec86f1e1984264eea3ddba124b73cf (diff) | |
download | method_source-2475bb9273c102e5fd3bfe778ab792635ff43cda.tar.gz |
version 0.3.5, now has support to take advantage of Method#source on rubinius
Diffstat (limited to 'lib/method_source.rb')
-rw-r--r-- | lib/method_source.rb | 24 |
1 files changed, 24 insertions, 0 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) |