Class Loader Weirdness | Rails 3.0.3

Hi guys,

I am stuck on, what i think is a class loader issue.

In my app/models directory i have the following files:

reductions/base.rb
reductions/conversions_by_bucket.rb
reductions/conversions_by_hour.rb
reductions/impressions_by_hour.rb

(background -- i am using mongoid, and i use these files to manage
mapReduce)

These classes only have class methods. In each of these classes I
added the following method:

def self.hello
  "hello"
end

And checkout this weirdness from the rails console:

Reductions::ImpressionsByHour.hello

=> "hello"

Reductions::ConversionsByHour.hello

=> "hello"

Reductions::ImpressionsByBucket.hello

NoMethodError: undefined method `hello' for
Reductions::ImpressionsByBucket:Class

BUT ...

require 'reductions/conversions_by_bucket.rb'

=> nil

Reductions::ConversionsByBucket.hello

=> "hello"

Soooooo weird!!! So why is reductions/conversions_by_bucket.rb not
being loaded by the class loader?!

I am using rails 3.0.3

Thanks!!

I have the feeling the class-names are bit mismatched. what is the
relation between Reductions::ConversionsByBucket and
Reductions::ImpressionsByBucket ?

- Kristian

Yeah I thought that too -- but i have looked it over hundreds of times
and can't find the mismatch. I have simplifed the classes to just
have the hello method. And still have the same behavior. Here are
the three classes

#app/models/reductions/impressions_by_hour.rb
class Reductions::ImpressionsByHour
  def self.hello
    "hello"
  end
end

#app/models/reductions/conversions_by_hour.rb
class Reductions::ConversionsByHour
  def self.hello
    "hello"
  end
end

#app/models/reductions/conversions_by_bucket.rb
class Reductions::ConversionsByBucket
  def self.hello
    "hello"
  end
end

ls app/models/reductions/
base.rb conversions_by_bucket.rb
conversions_by_hour.rb impressions_by_hour.rb unions.rb

The relationship between the classes is that they all perform map/
reduce methods. base.rb holds common code between them

I'm sure its something simple, but I am stumped!

-- Jonathan

I should add, that the class kind-of gets loaded, Checkout the
following rails console sequence:

[2] > Reductions::ConversionsByBucket
=> Reductions::ConversionsByBucket
[3] > Reductions::ConversionsByBucket.class
=> Class
[4] > Reductions::ConversionsByBucket.hello
NoMethodError: undefined method `hello' for
Reductions::ConversionsByBucket:Class

[5] > require 'reductions/conversions_by_bucket.rb'
=> nil
[6] > Reductions::ConversionsByBucket.hello
=> "hello"

I created a test app that highlights the problem:

https://github.com/jtushman/classloadingissue

Ok figured it out.

The AWS/SW gem overwrites Module#const_missing -- and messes with
things if you class ends in 'Bucket'. Man, that was a great use of 6
hrs. No idea why it only happens when coupled with
InheritedResources, but that clearly is the root of the problem.