summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authoryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-11 08:41:13 +0000
committeryugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-11-11 08:41:13 +0000
commitd1983054610a503fa797f6b82a8c57133b3f8e1e (patch)
treec0035d24db1c9a1e4f1bb1e7df63188dab469615 /lib
parentc5f6d62aa000238d3e8cd1c51521d78d223a4050 (diff)
downloadruby-d1983054610a503fa797f6b82a8c57133b3f8e1e.tar.gz
ruby-d1983054610a503fa797f6b82a8c57133b3f8e1e.tar.xz
ruby-d1983054610a503fa797f6b82a8c57133b3f8e1e.zip
merges r20126 from trunk into ruby_1_9_1.
* lib/yaml/rubytypes.rb: support Rational and Complex as 1.8 does. a patch from Hiroshi Moriyama in [ruby-dev:36899]. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_9_1@20184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/yaml/rubytypes.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/yaml/rubytypes.rb b/lib/yaml/rubytypes.rb
index 35b719196..ae65b355e 100644
--- a/lib/yaml/rubytypes.rb
+++ b/lib/yaml/rubytypes.rb
@@ -379,6 +379,44 @@ class Float
end
end
+class Rational
+ yaml_as "tag:ruby.yaml.org,2002:object:Rational"
+ def Rational.yaml_new( klass, tag, val )
+ if val.is_a? String
+ Rational( val )
+ else
+ Rational( val['numerator'], val['denominator'] )
+ end
+ end
+ def to_yaml( opts = {} )
+ YAML::quick_emit( self, opts ) do |out|
+ out.map( taguri, nil ) do |map|
+ map.add( 'denominator', denominator )
+ map.add( 'numerator', numerator )
+ end
+ end
+ end
+end
+
+class Complex
+ yaml_as "tag:ruby.yaml.org,2002:object:Complex"
+ def Complex.yaml_new( klass, tag, val )
+ if val.is_a? String
+ Complex( val )
+ else
+ Complex( val['real'], val['image'] )
+ end
+ end
+ def to_yaml( opts = {} )
+ YAML::quick_emit( self, opts ) do |out|
+ out.map( taguri, nil ) do |map|
+ map.add( 'image', imaginary )
+ map.add( 'real', real )
+ end
+ end
+ end
+end
+
class TrueClass
yaml_as "tag:yaml.org,2002:bool#yes"
def to_yaml( opts = {} )