# How to force 'const\_missing' in 'YAML.load'?

**URL:** <https://www.ruby-forum.com/t/how-to-force-const-missing-in-yaml-load/153369>\
**Category:** Ruby\
**Created:** [November 15, 2008, 9:47pm UTC](https://www.ruby-forum.com/t/how-to-force-const-missing-in-yaml-load/153369 "2008-11-15T21:47:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![axyd80](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@axyd80](https://www.ruby-forum.com/u/axyd80)\
**Post date:** [November 15, 2008, 9:47pm UTC](https://www.ruby-forum.com/t/how-to-force-const-missing-in-yaml-load/153369/1 "2008-11-15T21:47:41Z")

</div>

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?!
