summaryrefslogtreecommitdiff
path: root/lib/yaml/rubytypes.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/yaml/rubytypes.rb')
-rw-r--r--lib/yaml/rubytypes.rb43
1 files changed, 4 insertions, 39 deletions
diff --git a/lib/yaml/rubytypes.rb b/lib/yaml/rubytypes.rb
index ca7529217e..29be1b96fc 100644
--- a/lib/yaml/rubytypes.rb
+++ b/lib/yaml/rubytypes.rb
@@ -1,9 +1,6 @@
# -*- mode: ruby; ruby-indent-level: 4; tab-width: 4 -*- vim: sw=4 ts=4
require 'date'
-#
-# Type conversions
-#
class Class
def to_yaml( opts = {} )
raise TypeError, "can't dump anonymous class %s" % self.class
@@ -25,9 +22,6 @@ class Object
end
end
-#
-# Maps: Hash#to_yaml
-#
class Hash
yaml_as "tag:ruby.yaml.org,2002:hash"
yaml_as "tag:yaml.org,2002:map"
@@ -51,9 +45,6 @@ class Hash
end
end
-#
-# Structs: export as a !map
-#
class Struct
yaml_as "tag:ruby.yaml.org,2002:struct"
def self.yaml_tag_class_name; self.name.gsub( "Struct::", "" ); end
@@ -108,9 +99,6 @@ class Struct
end
end
-#
-# Sequences: Array#to_yaml
-#
class Array
yaml_as "tag:ruby.yaml.org,2002:array"
yaml_as "tag:yaml.org,2002:seq"
@@ -126,9 +114,6 @@ class Array
end
end
-#
-# Exception#to_yaml
-#
class Exception
yaml_as "tag:ruby.yaml.org,2002:exception"
def Exception.yaml_new( klass, tag, val )
@@ -150,10 +135,6 @@ class Exception
end
end
-
-#
-# String#to_yaml
-#
class String
yaml_as "tag:ruby.yaml.org,2002:string"
yaml_as "tag:yaml.org,2002:str"
@@ -194,9 +175,7 @@ class String
end
end
end
-#
-# Symbol#to_yaml
-#
+
class Symbol
yaml_as "tag:ruby.yaml.org,2002:symbol"
yaml_as "tag:ruby.yaml.org,2002:sym"
@@ -210,15 +189,11 @@ class Symbol
end
def to_yaml( opts = {} )
YAML::quick_emit( nil, opts ) do |out|
- out.scalar( taguri, self.id2name, :plain )
+ out.scalar( "tag:yaml.org,2002:str", self.inspect, :plain )
end
end
end
-#
-# Range#to_yaml
-# TODO: Rework the Range as a sequence (simpler)
-#
class Range
yaml_as "tag:ruby.yaml.org,2002:range"
def Range.yaml_new( klass, tag, val )
@@ -273,9 +248,6 @@ class Range
end
end
-#
-# Make an Regexp
-#
class Regexp
yaml_as "tag:ruby.yaml.org,2002:regexp"
def Regexp.yaml_new( klass, tag, val )
@@ -323,9 +295,6 @@ class Regexp
end
end
-#
-# Emit a Time object as an ISO 8601 timestamp
-#
class Time
yaml_as "tag:ruby.yaml.org,2002:time"
yaml_as "tag:yaml.org,2002:timestamp"
@@ -373,9 +342,6 @@ class Time
end
end
-#
-# Emit a Date object as a simple implicit
-#
class Date
yaml_as "tag:yaml.org,2002:timestamp#ymd"
def to_yaml( opts = {} )
@@ -385,9 +351,6 @@ class Date
end
end
-#
-# Send Integer, Booleans, NilClass to String
-#
class Numeric
def to_yaml( opts = {} )
YAML::quick_emit( nil, opts ) do |out|
@@ -403,9 +366,11 @@ class Numeric
end
end
end
+
class Fixnum
yaml_as "tag:yaml.org,2002:int"
end
+
class Float
yaml_as "tag:yaml.org,2002:float"
end