From 85a9520118f5dbbaab8a5801815c605c1bb799c1 Mon Sep 17 00:00:00 2001 From: Shugo Maeda Date: Tue, 23 Oct 2012 11:29:34 +0900 Subject: [PATCH] don't use RubyVM if it's not available. --- lib/immutable.rb | 16 ++++++++++------ test/test_helper.rb | 20 ++++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/immutable.rb b/lib/immutable.rb index d71485a..ad15a71 100644 --- a/lib/immutable.rb +++ b/lib/immutable.rb @@ -2,11 +2,13 @@ module Immutable end -old_compile_option = RubyVM::InstructionSequence.compile_option -RubyVM::InstructionSequence.compile_option = { - :tailcall_optimization => true, - :trace_instruction => false -} +if defined?(RubyVM) + old_compile_option = RubyVM::InstructionSequence.compile_option + RubyVM::InstructionSequence.compile_option = { + :tailcall_optimization => true, + :trace_instruction => false + } +end begin require_relative "immutable/list" require_relative "immutable/map" @@ -16,5 +18,7 @@ module Immutable require_relative "immutable/output_restricted_deque" require_relative "immutable/deque" ensure - RubyVM::InstructionSequence.compile_option = old_compile_option + if defined?(RubyVM) + RubyVM::InstructionSequence.compile_option = old_compile_option + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index d3ab630..84168a4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -3,14 +3,18 @@ require "test/unit" def with_tailcall_optimization - old_compile_option = RubyVM::InstructionSequence.compile_option - RubyVM::InstructionSequence.compile_option = { - :tailcall_optimization => true, - :trace_instruction => false - } - begin + if defined?(RubyVM) + old_compile_option = RubyVM::InstructionSequence.compile_option + RubyVM::InstructionSequence.compile_option = { + :tailcall_optimization => true, + :trace_instruction => false + } + begin + yield + ensure + RubyVM::InstructionSequence.compile_option = old_compile_option + end + else yield - ensure - RubyVM::InstructionSequence.compile_option = old_compile_option end end