From 831eb4566e62d496f5f3e74968e5e38ffa1af7c6 Mon Sep 17 00:00:00 2001 From: John Mair Date: Fri, 17 Dec 2010 14:38:10 +1300 Subject: replaced RubyVM::ISeq with Ripper; method_source should now work on all 1.9 Ruby implementations that support Ripper --- lib/method_source.rb | 22 +++++----------------- lib/method_source/version.rb | 2 +- 2 files changed, 6 insertions(+), 18 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 diff --git a/lib/method_source/version.rb b/lib/method_source/version.rb index 1f52d87..6461c90 100644 --- a/lib/method_source/version.rb +++ b/lib/method_source/version.rb @@ -1,3 +1,3 @@ module MethodSource - VERSION = "0.1.1" + VERSION = "0.1.4" end -- cgit v1.2.1