How to force 'const_missing' in 'YAML.load'?

A

Alexey Petrushin

Hello!

Is there a way to force 'const_missing' exception in 'YAML.load' if the
Class definition is not found?
By default if it can't find the class definition it just silently
instantiates the YAML::Object stub.

One solution is to add the Class to Domain Types. But for my situation
this is absolutely not suitable.

YAML.add_domain_type("TheClass,2007", "") do |type, val|
klass = eval(type.split(':').last)
YAML.object_maker(klass, val)
end

class TheClass
def to_yaml_type
"!TheClass,2007/#{self.class}"
end
end

Other - alter 'Module' in 'yaml/tag.rb'

class Module

# ...

def yaml_tag_read_class( name )
eval(name, TOPLEVEL_BINDING) << ADD THIS LINE
name
end
end

If i alter 'Module' in 'yaml/tag.rb' it works, but if i override it in
another place it doesn't. Why?!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,191
Latest member
BuyKetoBeez

Latest Threads

Top