Class: YAML::Pairs
Overview
Builtin collection: !pairs
Class Method Summary collapse
Instance Method Summary collapse
- #[](k) ⇒ Object
- #[]=(k, val) ⇒ Object
- #has_key?(k) ⇒ Boolean
- #is_complex_yaml? ⇒ Boolean
- #to_yaml(opts = {}) ⇒ Object
- #yaml_initialize(tag, val) ⇒ Object
Class Method Details
Instance Method Details
#[](k) ⇒ Object
164 165 166 |
# File 'lib/yaml/types.rb', line 164 def []( k ) self.assoc( k ).to_a end |
#[]=(k, val) ⇒ Object
167 168 169 170 |
# File 'lib/yaml/types.rb', line 167 def []=( k, val ) self << [ k, val ] val end |
#has_key?(k) ⇒ Boolean
171 172 173 |
# File 'lib/yaml/types.rb', line 171 def has_key?( k ) self.assoc( k ) ? true : false end |
#is_complex_yaml? ⇒ Boolean
174 175 176 |
# File 'lib/yaml/types.rb', line 174 def is_complex_yaml? true end |
#to_yaml(opts = {}) ⇒ Object
177 178 179 180 181 182 183 184 185 |
# File 'lib/yaml/types.rb', line 177 def to_yaml( opts = {} ) YAML::quick_emit( self.object_id, opts ) do |out| out.seq( taguri, to_yaml_style ) do |seq| self.each do |v| seq.add( Hash[ *v ] ) end end end end |
#yaml_initialize(tag, val) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/yaml/types.rb', line 143 def yaml_initialize( tag, val ) if Array === val val.each do |v| if Hash === v concat( v.to_a ) # Convert the map to a sequence else raise YAML::Error, "Invalid !pairs entry: " + val.inspect end end else raise YAML::Error, "Invalid !pairs: " + val.inspect end self end |