I plan move the "require" up top, once I've got my stuff straight.
Okay, I needed the "self." in the Module def.
< in ahs.rb >
module Ahs
class CreditCard
def self.test2
puts "\n\nself.CreditCard.test2 fired\n\n"
end
end
def self.test
puts "\n\nself.test fired\n\n"
end
end
< in offer_renewal_controller.rb >
Ahs.test
Ahs.CreditCard.test2
Result:
self.test fired
undefined method `CreditCard' for Ahs:Module [exception thrown]
What's wrong with the second statement?
Thanks helping,
Jason
On Dec 8, 11:12 am, Vincent Fourmond <vincent.fourm... / 9online.fr>
wrote:
> Jason Vogel wrote:
> > Disclaimer: Ruby Nuby
>
> > Source
>
> > module Test # (filename my_test.rb)
>
> > def test
> > puts "\n\ntest fired\n\n"
> > end
> > end
>
> > class OfferRenewalController < ApplicationController
>
> > def payment_made
>
> > require 'my_test'
>
> > Test.test
>
> > end
>
> > Error
> > NoMethodError in Offer renewalController#payment_made
>
> > private method `test' called for Test:Module
>
> > So what am I doing wrong? In the module, you did define test as an instance method. So if you
> want to use it, you should
>
> include Test
>
> If you want to use as Test.test, define it as
>
> module Test
> def Test.test
> [...]
>
> or
>
> module Test
> def self.test
> [...]
>
> The latter is better as if you decide to change the name of your module,
> you won't have to change the names of methods.
>
> By the way, I find it funny that you require 'my_test' from within a
> method. I believe it would be better to write
>
> require 'my_test'
>
> class OfferRenewalController < ApplicationController
> def payment_made
> Test.test
> end
> end
>
> Cheers,
>
> Vince
>
> --
> Vincent Fourmond, PhD studenthttp://vincent.fourmond.neuf.fr/