has_one association problem together with Object method override


I came across a peculiar problem with has_one association in combination with an Object method override. Can somebody explain to me what is going on?

Here is how it goes:

I have a 'has_one' relationship between Supplier and Account, like in the example of the has_one example used in Rails Guides.


class Supplier < ActiveRecord::Base

  validates :name, :presence => true

  has_one :account

  nilify_blanks end


class Account < ActiveRecord::Base

  belongs_to :supplier

  validates :supplier_id, :presence => true


  def foo     puts 'in account'   end

  def to_s     puts 'in account'   end


I also have a method foo on Object as follows:

class Object   def foo     puts 'in object'   end end

When I call:

Supplier#account#to_s I get 'in account'

When I call:

Supplier#account#foo I get 'in object'

whereas I would expect it to print 'in account'

Does anybody have any clue why does this happen? Is this a bug in Rails ActiveRecord?

Thanks in advance P.S. If you want, you can get a full fledged application that demonstrates the problem from here: