Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6194089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:14:10+00:00 2026-05-24T03:14:10+00:00

I’m working with DelayedJob and I need to override a method that I thought

  • 0

I’m working with DelayedJob and I need to override a method that I thought was being used when an object is deserialized from YAML: self.yaml_new (defined in in delayed/serialization/active_record)

My impression was that when YAML deserialized some data, it would call the yaml_new method on the class of the type of that data

DJ’s yaml_new method fetches the object from the database using the passed in id

I’m unable to achieve this behaviour with my own classes. When I set a self.yaml_new method on a class and try to YAML.load on a serialized instance, it doesn’t seem to call yaml_new so I must obviously be mistaken.

What then is this method for?

Searching for yaml_new doesn’t yield much (just API docs of other people using it). So I’m wondering what exactly this method is.

I figured yaml_new would be some hook method called when an object is found of some type if that method existed on the class. But again I can’t actually get this to work. Below is a sample:

class B
  def self.yaml_new(klass, tag, val)
    puts "I'm in yaml new!"
  end
end

b = B.new
YAML.load b.to_yaml    # expected "I'm in yaml new!" got nothing

updates

So after playing around in my Rails application, it appears that yaml_new does actually get called from YAML.load. I have a file in there like so:

module ActiveRecord
  class Base

    def self.yaml_new(klass, tag, val)
      puts "\n\n yaml_new!!!\n\n"
      klass.find(val['attributes']['id'])
    rescue ActiveRecord::RecordNotFound
      raise Delayed::DeserializationError
    end

    def to_yaml_properties
      ['@attributes', '@database']    # add in database attribute for serialization
    end

  end
end

Which is just what DJ does, except I’m logging the action.

YAML.load Contact.first.to_yaml
# => yaml_new!!!

I actually get the logged output!!

So what am I doing wrong outside of my Rails app?? Is there some other way of getting this method to trigger?? I ask because I’m trying to test this in my own gem and the yaml_new method doesn’t trigger, so my tests fail, and yet it actually does work inside Rails

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:14:11+00:00Added an answer on May 24, 2026 at 3:14 am

    You need to add something like

    yaml_as "tag:ruby.yaml.org,2002:B"
    

    before the definition of the self.yaml_new method. According to the comments in yaml/tag.rb, yaml_as:

    Adds a taguri tag to a class, used when dumping or loading the class
    in YAML. See YAML::tag_class for detailed information on typing and
    taguris.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.