diff options
author | John Mair <jrmair@gmail.com> | 2010-12-17 14:38:10 +1300 |
---|---|---|
committer | John Mair <jrmair@gmail.com> | 2010-12-17 14:39:44 +1300 |
commit | 831eb4566e62d496f5f3e74968e5e38ffa1af7c6 (patch) | |
tree | 6e43e3730cda4d811d6276e96b8355440d7d7315 /lib/method_source.rb | |
parent | 18af7555f4dd1a0d7ab6904a59ad55d36d0fa073 (diff) | |
download | method_source-831eb4566e62d496f5f3e74968e5e38ffa1af7c6.tar.gz |
replaced RubyVM::ISeq with Ripper; method_source should now work on all 1.9 Ruby implementations that support Ripper
Diffstat (limited to 'lib/method_source.rb')
-rw-r--r-- | lib/method_source.rb | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/lib/method_source.rb b/lib/method_source.rb index 59c98f3..57397c7 100644 --- a/lib/method_source.rb +++ b/lib/method_source.rb @@ -6,6 +6,10 @@ direc = File.dirname(__FILE__) require 'stringio' require "#{direc}/method_source/version" +if RUBY_VERSION =~ /1.9/ + require 'ripper' +end + module MethodSource # Helper method used to find end of method body @@ -13,23 +17,7 @@ module MethodSource # correctness # @return [Boolean] def self.valid_expression?(code) - suppress_stderr do - RubyVM::InstructionSequence.new(code) - end - rescue Exception - false - else - true - end - - # Helper method used to suppress stderr output by the - # `RubyVM::InstructionSequence` method - # @yield The block where stderr is suppressed - def self.suppress_stderr - real_stderr, $stderr = $stderr, StringIO.new - yield - ensure - $stderr = real_stderr + !!Ripper::SexpBuilder.new(code).parse end # Helper method responsible for opening source file and advancing to |