weird ArgumentError in non-ActiveRecord models

Hi,

I have a rails (2.3.5) project that has two models that are not
ActiveRecord based - one is called Wiki and another is called WebApi.

I have been using this in the past, and it was working. However,
something I did is now causing ArgumentError to be raised when I call
a class method on WebApi from a Wiki class method. Here is the
relevant code:

wiki.rb

class Wiki
  def self.get_url phrase=''
    response = WebApi.format_and_call(WIKIPEDIA_URL, phrase) #error
occurs here
  ...
  end
  ...
end

web_api.rb

class WebApi
  def self.format_and_call url_format_string, phrase)
    ...
  end
end

Here is the error I get:

ArgumentError (wrong number of arguments (0 for 1)):
  app/models/wiki.rb:7:in `get_url'

On debugging, i notice that the error is coming from a const_missing
triggered by the attempt to access the WebApi object (it has nothing
to do with the Wikipedia Url constant, which is fine). Here is the
debug session:

/(rdb:18) step
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/
gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:
91
if [Object, Kernel].include?(self) || parent == self
(rdb:18) step
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/
gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/module/
introspection.rb:31
parent_name ? parent_name.constantize : Object
(rdb:18) step
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/
gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/module/
introspection.rb:8
unless defined? @parent_name
(rdb:18) next
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/
gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/module/
introspection.rb:9
@parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
(rdb:18) next
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/
gems/1.8/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:162
rescue_action(exception)
(rdb:18) exception
#<ArgumentError: wrong number of arguments (0 for 1)>

I had initially named the WebApi class as Web, and thought the problem
may be due to a name collision, but I tried different names, and get
the same problem.

I am quite confused, since this seems fairly simple code, and I don't
know where to look.

I am using devise, and have delayed_job as well in the project, but
not really using it in this case.

Thanks
Anand

I have tried several things in the last few hours - including
branching, ripping out all the files, and adding the code back one bit
at a time. I am really out of choices now - one interesting thing -
this error seems to occur only on the rails app codepath. When I call
the same function from a unit test, it works fine.

I did suspect that this was due to some gem being out of sync, as
several articles suggested, so I have removed everything except uri,
open-uri and nokogiri. It still does repro.

Can someone please advise- at this point, any suggestion is useful.

Thanks
Anand

I got a very ugly workaround to work - I created a fresh project from
scratch (no git, no delayed job, no devise, nothing:-)) and added the
files in. Then I merged the non-active record models into one (non AR)
model. So, all calls are within the same class, and this works.

The interesting thing is that the error occurs only where I have calls
from one non-AR model to another. When i call a non-AR model from an
AR model it works.

I dont like this at all, since each of the non-AR models is a separate
model for a reason (at the least to share common code).

Also, i checked out an old branch that had the same scenario, but
somewhat different code - i.e, it had non-AR models talking to each
other, but it had no ajax whatsoever (the problems I mentioned occured
in a project that has ajax views, rjs, etc.). That branch works fine
on the local machine, so this doesnt seem like an environment problem
on the machine...

Any pointers would be very helpful, as I dont want to hang on to this
workaround for too long.

Thanks
Anand

BTW, there is a typo in the code snippet where I am missing an open
parenthesis. Adding it also causes the problem.
Can anybody help, please?

Thanks