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...

dvdplm ยท Feb 5, 20091 thank

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...
  1. an instance of klass is allocated
  2. an instance of string is initialized, with the val parameter, and bound to the class context
  3. 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!!

:)