summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/yaml/basenode.rb14
-rw-r--r--lib/yaml/rubytypes.rb5
2 files changed, 10 insertions, 9 deletions
diff --git a/lib/yaml/basenode.rb b/lib/yaml/basenode.rb
index a98f6d890a..7072b1dcd6 100644
--- a/lib/yaml/basenode.rb
+++ b/lib/yaml/basenode.rb
@@ -67,8 +67,8 @@ module YAML
end
def at( seg )
- if Hash === @value and @value.has_key?( seg )
- @value[seg][1]
+ if Hash === @value
+ self[seg]
elsif Array === @value and seg =~ /\A\d+\Z/ and @value[seg.to_i]
@value[seg.to_i]
end
@@ -99,8 +99,8 @@ module YAML
@value.collect { |v|
idx += 1
if Hash === @value
- match_init = [v[0], v[1][1]]
- match_deep = v[1][1].match_segment( ypath, depth )
+ match_init = [v[0].transform, v[1]]
+ match_deep = v[1].match_segment( ypath, depth )
else
match_init = [idx, v]
match_deep = v.match_segment( ypath, depth )
@@ -127,7 +127,7 @@ module YAML
@value.collect { |h|
idx += 1
if Hash === @value
- [h[0], h[1][1]]
+ [h[0].transform, h[1]]
else
[idx, h]
end
@@ -182,9 +182,9 @@ module YAML
# We want the node to act like as Hash
# if it is.
#
- def []( *k )
+ def []( *key )
if Hash === @value
- v = @value.[]( *k )
+ v = @value.detect { |k,v| k.transform == key.first }
v[1] if v
elsif Array === @value
@value.[]( *k )
diff --git a/lib/yaml/rubytypes.rb b/lib/yaml/rubytypes.rb
index 29be1b96fc..10516d7557 100644
--- a/lib/yaml/rubytypes.rb
+++ b/lib/yaml/rubytypes.rb
@@ -137,6 +137,7 @@ end
class String
yaml_as "tag:ruby.yaml.org,2002:string"
+ yaml_as "tag:yaml.org,2002:binary"
yaml_as "tag:yaml.org,2002:str"
def is_complex_yaml?
to_yaml_style or not to_yaml_properties.empty? or self =~ /\n.+/
@@ -145,6 +146,7 @@ class String
( self.count( "^ -~", "^\r\n" ) / self.size > 0.3 || self.count( "\x00" ) > 0 ) unless empty?
end
def String.yaml_new( klass, tag, val )
+ val = val.unpack("m")[0] if tag == "tag:yaml.org,2002:binary"
val = { 'str' => val } if String === val
if Hash === val
s = klass.allocate
@@ -163,7 +165,7 @@ class String
if is_binary_data?
out.scalar( "tag:yaml.org,2002:binary", [self].pack("m"), :literal )
elsif to_yaml_properties.empty?
- out.scalar( taguri, self, to_yaml_style )
+ out.scalar( taguri, self, self =~ /^:/ ? :quote2 : to_yaml_style )
else
out.map( taguri, to_yaml_style ) do |map|
map.add( 'str', "#{self}" )
@@ -179,7 +181,6 @@ end
class Symbol
yaml_as "tag:ruby.yaml.org,2002:symbol"
yaml_as "tag:ruby.yaml.org,2002:sym"
- # yaml_implicit /^:/, :yaml_new
def Symbol.yaml_new( klass, tag, val )
if String === val
val.intern