Forum: Ruby on Rails Can you override a private rails method?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
joshuabates (Guest)
on 2005-12-04 04:43
(Received via mailing list)
I'm trying to override the behavior of find_with_associations for an
acts_as
plugin.

Not having much luck as it's a private method, so I can't alias it, and
my
method
of the same name is ignored.

Is this even possible?

joshua
petermichaux (Guest)
on 2005-12-04 05:28
(Received via mailing list)
In the ruby example below, it looks like you can override a private
function. Can you post code?

-Peter


class A
  private
  def foo
     "foo"
  end
end

class A
  private
  def foo
     "foofoo"
  end

  public
  def bar
    foo
  end
end

a = A.new
puts a.bar  # outputs "foofoo"
joshuabates (Guest)
on 2005-12-04 06:20
(Received via mailing list)
In the process of grabbing my code to post, I solved it!!!

I had to include the methods straight into ActiveRecord::Base not into
ActiveRecord::Associations

eg
ActiveRecord::Base.send   :include,
Democracy::Acts::Multilingual::Associations


I was worried that it just wasn't possible, because doing something as
simple as this doesn't work

module ActiveRecord
    module Associations
        private
        def association_join(*args)
            breakpoint
            super
        end
    end
end
This topic is locked and can not be replied to.