Project

General

Profile

Bug #667

yaml が Complex、Rational をうまくあつかえていない

Added by tadf (tadayoshi funaba) almost 12 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
Backport:

Description

=begin
組み込みに対応できていません。

main@187-20080811> Rational(1,2).to_yaml
#=> "--- !ruby/object:Rational \ndenominator: 2\nnumerator: 1\n"
main@187-20080811> YAML.load(Rational(1,2).to_yaml)
#=> Rational(1, 2)

main@190-20081020> Rational(1,2).to_yaml
#=> "--- !ruby/object:Rational {}\n\n"
main@190-20081020> YAML.load(Rational(1,2).to_yaml)
#=> (0/1)
=end


Files

yaml-fix-suport-for-ratoinal-and-complex.diff (2.16 KB) yaml-fix-suport-for-ratoinal-and-complex.diff hiroshi (Hiroshi MORIYAMA), 10/24/2008 02:29 PM
#1

Updated by hiroshi (Hiroshi MORIYAMA) almost 12 years ago

=begin
Quoted from URL:http://redmine.ruby-lang.org/issues/show/667:

組み込みに対応できていません。

main@187-20080811> Rational(1,2).to_yaml
#=> "--- !ruby/object:Rational \ndenominator: 2\nnumerator: 1\n"
main@187-20080811> YAML.load(Rational(1,2).to_yaml)
#=> Rational(1, 2)

main@190-20081020> Rational(1,2).to_yaml
#=> "--- !ruby/object:Rational {}\n\n"
main@190-20081020> YAML.load(Rational(1,2).to_yaml)
#=> (0/1)

このパッチ(redmineに添付)でどうでしょうか。互換性を保つため、
ruby 1.8.5 以降と同じ形式のYAMLデータを読み書きする様にしまし
た。次の様になります:

% ruby1.8 -v
ruby 1.8.7 (2008-10-22 revision 19775) [i686-linux]
% ruby1.8 -ryaml -rrational -e 'puts Rational(1,2).to_yaml' > /tmp/ruby_1_8_rational.yaml
% cat /tmp/ruby_1_8_rational.yaml
--- !ruby/object:Rational
denominator: 2
numerator: 1
% ruby -ryaml -ve 'p YAML.load(ARGF.read)' < /tmp/ruby_1_8_rational.yaml
ruby 1.9.0 (2008-10-24 revision 19843) i686-linux
% ruby -ryaml -e 'puts Rational(1,2).to_yaml' > /tmp/ruby_1_9_rational.yaml
% diff /tmp/ruby_1_8_rational.yaml /tmp/ruby_1_9_rational.yaml
%

ついでに ruby 1.8.3 の形式の読取にも対応してあります(1.8.4は
コンパイルできなかったので未確認):

% ruby1.8.3 -v
ruby 1.8.3 (2005-09-21) [i686-linux]
% ruby1.8.3 -ryaml -rrational -e 'puts Rational(1,2).to_yaml' > /tmp/ruby_1_8_3_rational.yaml
% cat /tmp/ruby_1_8_3_rational.yaml
!ruby/object:Rational 1/2
% ruby -ryaml -ve 'p YAML.load(ARGF.read)' < /tmp/ruby_1_8_3_rational.yaml
ruby 1.9.0 (2008-10-24 revision 19843) i686-linux
%

-- Hiroshi Moriyama hiroshi@kvd.biglobe.ne.jp
=end

#2

Updated by matz (Yukihiro Matsumoto) almost 12 years ago

  • Status changed from Open to Closed

=begin
fixed by r20126
=end

Also available in: Atom PDF