summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/method_source.rb22
-rw-r--r--lib/method_source/version.rb2
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