summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/yaml.rb16
-rw-r--r--lib/yaml/rubytypes.rb13
2 files changed, 12 insertions, 17 deletions
diff --git a/lib/yaml.rb b/lib/yaml.rb
index 1b2a4ea81f..b5852b2257 100644
--- a/lib/yaml.rb
+++ b/lib/yaml.rb
@@ -105,17 +105,19 @@ module YAML
end
#
+ # Detect typing of a string
+ #
+ def YAML.detect_implicit( val )
+ @@loader.detect_implicit( val )
+ end
+
+ #
# Method to extract colon-seperated type and class, returning
# the type and the constant of the class
#
def YAML.read_type_class( type, obj_class )
- type =~ /^([^:]+):(.+)/i
- if $2
- type = $1
- $2.split( "::" ).each { |c|
- obj_class = obj_class.const_get( c )
- }
- end
+ scheme, domain, type, tclass = type.split( ':', 4 )
+ tclass.split( "::" ).each { |c| obj_class = obj_class.const_get( c ) } if tclass
return [ type, obj_class ]
end
diff --git a/lib/yaml/rubytypes.rb b/lib/yaml/rubytypes.rb
index 727c31ca78..3d4992a29f 100644
--- a/lib/yaml/rubytypes.rb
+++ b/lib/yaml/rubytypes.rb
@@ -160,25 +160,18 @@ class Struct
end
YAML.add_ruby_type( 'struct' ) { |type, val|
- type =~ /^struct:(\w+)/
if Hash === val
- type = $1
- struct_type = nil
- struct_def = []
- struct_name = ""
- if $1.to_s.length > 1
- struct_name = $1[0..$1.length]
- struct_def << struct_name
- end
+ struct_type = nil
#
# Use existing Struct if it exists
#
begin
- struct_type = Struct.const_get( struct_name )
+ struct_name, struct_type = YAML.read_type_class( type, Struct )
rescue NameError
end
if not struct_type
+ struct_def = [ type.split( ':', 4 ).last ]
struct_type = Struct.new( *struct_def.concat( val.keys.collect { |k| k.intern } ) )
end