summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--lib/yaml.rb25
2 files changed, 20 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 849a6f5d1f..bc62802a09 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Mon Jun 13 12:51:51 2011 NARUSE, Yui <naruse@ruby-lang.org>
+
+ * lib/yaml.rb: load psych only when syck is not loaded.
+
Mon Jun 13 12:23:39 2011 NARUSE, Yui <naruse@ruby-lang.org>
Mon Jun 13 12:23:39 2011 NARUSE, Yui <naruse@ruby-lang.org>
diff --git a/lib/yaml.rb b/lib/yaml.rb
index dd89a30e3f..eb0427a9d4 100644
--- a/lib/yaml.rb
+++ b/lib/yaml.rb
@@ -13,7 +13,7 @@ module YAML
def yamler= engine
raise(ArgumentError, "bad engine") unless %w{syck psych}.include?(engine)
- require engine
+ require engine unless (engine == 'syck' ? Syck : Psych).const_defined?(:VERSION)
Object.class_eval <<-eorb, __FILE__, __LINE__ + 1
remove_const 'YAML'
@@ -30,16 +30,23 @@ module YAML
ENGINE = YAML::EngineManager.new
end
-begin
- require 'psych'
-rescue LoadError
- warn "#{caller[0]}:"
- warn "It seems your ruby installation is missing psych (for YAML output)."
- warn "To eliminate this warning, please install libyaml and reinstall your ruby."
+if defined?(Psych)
+ engine = 'psych'
+elsif defined?(Syck)
+ engine = 'syck'
+else
+ begin
+ require 'psych'
+ engine = 'psych'
+ rescue LoadError
+ warn "#{caller[0]}:"
+ warn "It seems your ruby installation is missing psych (for YAML output)."
+ warn "To eliminate this warning, please install libyaml and reinstall your ruby."
+ require 'syck'
+ engine = 'syck'
+ end
end
-engine = (!defined?(Syck) && defined?(Psych) ? 'psych' : 'syck')
-
module Syck
ENGINE = YAML::ENGINE
end