summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mair <jrmair@gmail.com>2010-12-17 14:38:10 +1300
committerJohn Mair <jrmair@gmail.com>2010-12-17 14:39:44 +1300
commit831eb4566e62d496f5f3e74968e5e38ffa1af7c6 (patch)
tree6e43e3730cda4d811d6276e96b8355440d7d7315
parent18af7555f4dd1a0d7ab6904a59ad55d36d0fa073 (diff)
downloadmethod_source-831eb4566e62d496f5f3e74968e5e38ffa1af7c6.tar.gz
replaced RubyVM::ISeq with Ripper; method_source should now work on all 1.9 Ruby implementations that support Ripper
-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