title: Serialization/Deserialization ruby object in YAML
body: <p>I'm trying to understand the serialization/deserialization of ruby object using YAML under 1.8.7 and 1.9+ and have a few queries regarding it (I can't find much documentation on this)</p>
  
  <h3>Ruby 1.8.7</h3>
  
  <pre><code>class Element
      yaml_as "tag:ruby.yaml.org,2002:Element"
  
      def self.yaml_new(klass, tag, val)
        puts "print you are in yaml"
      end
    end
  
  
    YAML.parser
    =&gt; syck     ## parser is set as syck all good     
     e =  Element.new.to_yaml
     =&gt; "--- !ruby/Element {}\n\n" 
  </code></pre>
  
  <p>Question 1: Now why didn't I get <code>tag:ruby.yaml.org,2002:Element</code> instead of <code>--- !ruby/Element {}\n\n</code> ?</p>
  
  <pre><code>  YAML.load(e) 
    =&gt;  print your are in "yaml" ##print statement execute all good 
  
    ## Not sure who to change the parser in 1.8 to `pysch` so skipping this part
  </code></pre>
  
  <h3>Ruby 1.9+</h3>
  
  <pre><code>  YAML::ENGINE.yamler
     =&gt; pysch 
     e =  Element.new.to_yaml  
     =&gt; "--- !&lt;tag:ruby.yaml.org,2002:Element&gt; {}\n"  ## I see the tag in 1.9+ fine 
  </code></pre>
  
  <p>Question 2 :  Why is it working in 1.9+ and not in 1.8.7 ?</p>
  
  <pre><code>   YAML.load(e)
     =&gt;    ## The print is not getting printed 
  </code></pre>
  
  <p>Question 3: Why <code>print you are in yaml</code> isn't getting printed? In other words, why is <code>self.yaml_new</code> not getting invoked on <code>YAML.load</code>? Is it not supported under 1.9+ ?</p>
  
  <pre><code>   YAML::ENGINE.yamler = 'syck'
     =&gt; syck
     u =  Element.new.to_yaml
     =&gt; "--- !ruby/object:Element {}\n\n" 
  </code></pre>
  
  <p>Question 4 (similar to question #1) : Why is the the tag(<code>tag:ruby.yaml.org,2002:Element</code>) missing in the <code>serialize</code> yaml above</p>
  
  <pre><code>   YAML.load(e)
     =&gt;  ## Suprisingly, print is not executed 
  </code></pre>
  
  <p>Question 5 (similar to question #2): Why isn't <code>self.yaml_new</code> getting executed for <strong>syck</strong> and <strong>pysch</strong> parser in ruby 1.9+ ?</p>
  
  <p>Can anyone can help me resolve these questions?</p>