method
yaml_new
v1_8_7_72 -
Show latest stable
- Class:
String
yaml_new( klass, tag, val )public
No documentation available.
# File lib/yaml/rubytypes.rb, line 148
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
# Thank you, NaHi
String.instance_method(:initialize).
bind(s).
call( val.delete( 'str' ) )
val.each { |k,v| s.instance_variable_set( k, v ) }
s
else
raise YAML::TypeError, "Invalid String: " + val.inspect
end
end 1Note
Weird method...
Takes three params:
- a Class constant (has to be an existing class)
- a "tag" param that, if set to "tag:yaml.org,2002:binary" will call unpack("m") on the third parameter, val; any other values for tag are ignored
- val can be a Hash or a String; if it's a string it is wrapped in a hash {'str' => val}, other wise...
- an instance of klass is allocated
- an instance of string is initialized, with the val parameter, and bound to the class context
- for each key in val (if any!), set instance variables in the instantiated class
So, what does this method do, a part from making my eyes hurt? It loads a yaml file and instantiates a class and sets the ivars found in the yaml file. Sorta.
It is probably the worst code I have ever seen in the ruby standard libs. WTF!!
:)