I want to have methods in a module that are not accessible to the class that the module includes. In the following example:
class Foo include Bar def do_stuff common_method_name end end module Bar def do_stuff common_method_name end private def common_method_name
I want Foo.new.do_stuff to explode because it is trying to access the method that the module is trying to hide from it. In the above code, Foo.new.do_stuff will work fine: (
Is there a way to achieve what I want to do in Ruby?
UPDATE - real code
class Place < ActiveRecord::Base include RecursiveTreeQueries belongs_to :parent, {:class_name => "Place"} has_many :children, {:class_name => 'Place', :foreign_key => "parent_id"} end module RecursiveTreeQueries def self_and_descendants model_table = self.class.arel_table temp_table = Arel::Table.new :temp r = Arel::SelectManager.new(self.class.arel_engine).from(model_table).project(model_table.columns).join(temp_table).on('true').where(model_table[:parent_id].eq(temp_table[:id])) nr = Place.scoped.where(:id => id) q = Arel::SelectManager.new(self.class.arel_engine) as = Arel::Nodes::As.new temp_table, nr.union(r) arel = Arel::SelectManager.new(self.class.arel_engine).with(:recursive,as).from(temp_table).project(temp_table[:id]) self.class.where(model_table[:id].in(arel)) end def self_and_ascendants model_table = self.class.arel_table temp_table = Arel::Table.new :temp r = Arel::SelectManager.new(self.class.arel_engine).from(model_table).project(model_table.columns).join(temp_table).on('true').where(temp_table[:parent_id].eq(model_table[:id])) nr = Place.scoped.where(:id => id) q = Arel::SelectManager.new(self.class.arel_engine) as = Arel::Nodes::As.new temp_table, nr.union(r) arel = Arel::SelectManager.new(self.class.arel_engine).with(:recursive,as).from(temp_table).project(temp_table[:id]) self.class.where(model_table[:id].in(arel)) end end
Obviously, this code is hacked and caused by serious refactoring, and the purpose of my question is to find out if there is a way to reorganize this module with impunity from accidentally rewriting any method on ActiveRecord :: Base or any other module included in Place .rb.
source share