mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/yaml/rubytypes.rb (Fixnum): Bignum could not be loaded in
ruby 1.8.3/1.8.4. [ruby-core:6115] * lib/yaml/rubytypes.rb (Numeric): Subclass of Numeric could not be dumped properly. [ruby-core:7047] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9816 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
163224f639
commit
12d3325346
3 changed files with 37 additions and 10 deletions
|
@ -1,3 +1,11 @@
|
|||
Tue Jan 10 12:47:41 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||
|
||||
* lib/yaml/rubytypes.rb (Fixnum): Bignum could not be loaded in
|
||||
ruby 1.8.3/1.8.4. [ruby-core:6115]
|
||||
|
||||
* lib/yaml/rubytypes.rb (Numeric): Subclass of Numeric could not
|
||||
be dumped properly. [ruby-core:7047]
|
||||
|
||||
Tue Jan 10 12:00:48 2006 Aaron Schrab <aaron @nospam@ schrab.com>
|
||||
|
||||
* lib/yaml/rubytypes.rb (Symbol#yaml_new): YAML loading of quoted
|
||||
|
|
|
@ -353,7 +353,17 @@ class Date
|
|||
end
|
||||
end
|
||||
|
||||
class Numeric
|
||||
class Integer
|
||||
yaml_as "tag:yaml.org,2002:int"
|
||||
def to_yaml( opts = {} )
|
||||
YAML::quick_emit( nil, opts ) do |out|
|
||||
out.scalar( "tag:yaml.org,2002:int", self.to_s, :plain )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Float
|
||||
yaml_as "tag:yaml.org,2002:float"
|
||||
def to_yaml( opts = {} )
|
||||
YAML::quick_emit( nil, opts ) do |out|
|
||||
str = self.to_s
|
||||
|
@ -364,19 +374,11 @@ class Numeric
|
|||
elsif str == "NaN"
|
||||
str = ".NaN"
|
||||
end
|
||||
out.scalar( taguri, str, :plain )
|
||||
out.scalar( "tag:yaml.org,2002:float", str, :plain )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Fixnum
|
||||
yaml_as "tag:yaml.org,2002:int"
|
||||
end
|
||||
|
||||
class Float
|
||||
yaml_as "tag:yaml.org,2002:float"
|
||||
end
|
||||
|
||||
class TrueClass
|
||||
yaml_as "tag:yaml.org,2002:bool#yes"
|
||||
def to_yaml( opts = {} )
|
||||
|
|
|
@ -1236,6 +1236,23 @@ EOY
|
|||
assert_cycle(:"^foo")
|
||||
end
|
||||
|
||||
#
|
||||
# Test Numeric cycle
|
||||
#
|
||||
class NumericTest < Numeric
|
||||
def initialize(value)
|
||||
@value = value
|
||||
end
|
||||
def ==(other)
|
||||
@value == other.instance_eval{ @value }
|
||||
end
|
||||
end
|
||||
def test_numeric_cycle
|
||||
assert_cycle(1) # Fixnum
|
||||
assert_cycle(111111111111111111111111111111111) # Bignum
|
||||
assert_cycle(NumericTest.new(3)) # Subclass of Numeric
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if $0 == __FILE__
|
||||
|
|
Loading…
Add table
Reference in a new issue