Model Name Conflict

Thanks Ar Chon for the prompt response. But that runs me to another question.

How is Filter.find() different from ::Filter.find()?

::Filter makes ruby look from the top of the name space, so if you have

module Foo   class Filter   end

  def get_filter     ::Filter   end end

class Filter end

then the :: means you get the top level Filter class rather than Foo::Filter

Fred

Thanks for the clarification Frederick. So if I am not wrong top level class is nothing but in the Object level space, isn't it?

I believe so.

Also your lack of response for my other question "how does these effect the Dependencies mechanism?", I am assuming it shouldn't be a problem. As we are asking ruby to look for the top level class, it is the same as asking Filter.find() as in the case we would generally do when there is no conflicting class is my situation.

And finally I am assuming from the your example (with my additional method):

module Foo class Filter end

def get_filter ::Filter end

def get_my_filter self::Filter (or) Filter (same as self::Filter) end end

def get_outer_filter self::Filter end

class Filter end

get_filter -> returns outer class Filter get_my_filter -> returns Foo::Filter get_outer_filter -> returns outer class Filter

so self::Filter depends in the context of self. Any corrections are appreciated.

Filter and self::Filter are not the same, because constants are looked up lexically eg:

module Foo   class Filter     def self.name; 'inner'; end   end

  def self.included(base)     base.extend(ClassMethods)   end   module ClassMethods     def with_self       self::Filter     end

    def bare       Filter     end   end end

class Bar   class Filter     def self.name; 'from bar'; end   end   include Foo end

Then Bar.bare.name #=> "inner" Bar.with_self.name #=> "from bar"

Fred