<p>(sorry I should have been clearer with the code the first time I posted this. Hope this makes sense)</p>

<p>File "size_specification.rb"</p>

<pre><code>class SizeSpecification
  def fits?     
  end
end
</code></pre>

<p>File "some_module.rb"</p>

<pre><code>require 'size_specification'

module SomeModule
  def self.sizes
    YAML.load_file(File.dirname(__FILE__) + '/size_specification_data.yml')
  end
end
</code></pre>

<p>File "size_specification_data.yml</p>

<pre><code>--- 
- !ruby/object:SizeSpecification 
  height: 250
  width: 300
</code></pre>

<p>Then when I call</p>

<pre><code>SomeModule.sizes.first.fits?
</code></pre>

<p>I get an exception because "sizes" are Object's not SizeSpecification's so they don't have a "fits" function.</p>

[{'answer_id': 80075, 'author': 'robertpostill', 'author_id': 11219, 'author_profile': 'https://Stackoverflow.com/users/11219', 'pm_score': 0, 'selected': False, 'text': "<p>On second reading I'm a little confused, you seem to want to mix the class into module, which is porbably not so advisable.  Also is the YAML supposed to load an array of the SizeSpecifications?</p>\n\n<p>It appears to be that you're not mixing the Module into your class.  If I run the test in irb then the require throws a LoadError. So I assume you've put two files together, if not dump it.</p>\n\n<p>Normally you'd write the functionality in the module, then mix that into the class.  so you may modify your code like this:</p>\n\n<pre><code>class SizeSpecification\n  include SomeModule\n  def fits?     \n  end\nend\n</code></pre>\n\n<p>Which will allow you to then say:</p>\n\n<pre><code>SizeSpecification::SomeModule.sizes\n</code></pre>\n\n<p>I think you should also be able to say:</p>\n\n<pre><code>SizeSpecification.sizes\n</code></pre>\n\n<p>However that requires you to take the self off the prefix of the sizes method definition.</p>\n\n<p>Does that help?</p>\n"}, {'answer_id': 94745, 'author': 'anshul', 'author_id': 17674, 'author_profile': 'https://Stackoverflow.com/users/17674', 'pm_score': 1, 'selected': False, 'text': '<p>Are your settings and ruby installation ok?  I created those 3 files and wrote what follows in "test.rb"</p>\n\n<pre><code>require \'yaml\'\nrequire "some_module"\n\nSomeModule.sizes.first.fits?\n</code></pre>\n\n<p>Then I ran it.</p>\n\n<pre><code>$ ruby --version\nruby 1.8.6 (2008-06-20 patchlevel 230) [i486-linux]\n$ ruby -w test.rb \n$\n</code></pre>\n\n<p>No errors!</p>\n'}, {'answer_id': 103678, 'author': 'fatgeekuk', 'author_id': 17518, 'author_profile': 'https://Stackoverflow.com/users/17518', 'pm_score': 0, 'selected': False, 'text': "<p>The question code got me a little confused.</p>\n\n<p>In general with Ruby, if that happens it's a good sign that I am trying to do things the wrong way.</p>\n\n<p>It might be better to ask a question related to your actual intended outcome, rather than the specifics of a particular 'attack' on your problem. They we can say 'nonono, don't do that, do THIS' or 'ahhhhh, now I understand what you wanna do'</p>\n"}]
['https://Stackoverflow.com/questions/79466', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/14796/']