1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/lib/yaml.rb
tenderlove 4eaf3d4a51 * lib/yaml.rb: switch default YAML engine to Psych, old syck engine
may be enabled via YAML::ENGINE.yamler = "syck". [ruby-core:36374]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-23 19:05:47 +00:00

51 lines
994 B
Ruby

module YAML
class EngineManager # :nodoc:
attr_reader :yamler
def initialize
@yamler = nil
end
def syck?
'syck' == @yamler
end
def yamler= engine
raise(ArgumentError, "bad engine") unless %w{syck psych}.include?(engine)
require engine
Object.class_eval <<-eorb, __FILE__, __LINE__ + 1
remove_const 'YAML'
YAML = #{engine.capitalize}
remove_method :to_yaml
alias :to_yaml :#{engine}_to_yaml
eorb
@yamler = engine
engine
end
end
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."
end
engine = (!defined?(Syck) && defined?(Psych) ? 'psych' : 'syck')
module Syck
ENGINE = YAML::ENGINE
end
module Psych
ENGINE = YAML::ENGINE
end
YAML::ENGINE.yamler = engine