0

I have this class:

module App
  module Tools
    module Pollers
      class Kpi
        ...

I am in the rails console and I am trying to do something like this:

x = App::Tools::Pollers::Kpi.new

The system does not give an error, but it doesn't do anything when I try to work with the new object.

Did I have to set up something in routes.rb to allow this kind of nesting of modules? Or am I just not working with the file correctly? How do I output results to the screen of the console?

Here is what some console output looks like:

?> kpi_poller = App::Tools::Pollers::Kpi.new(date_1,date_2)
>> kpi_poller.do_launch
>> kpi_poller.do_launch("1");
?> ;
?> 

Thanks!

Genadinik
  • 18,153
  • 63
  • 185
  • 284
  • Can you explain what you mean by "doesn't do anything"? A sample of actual console output would help. – Rob Davis Jun 06 '12 at 15:05
  • @RobDavis I just added some console output to my original question :) The do_launch has some puts calls to output, but the console doesn't output any of those. Should they be logger instead? – Genadinik Jun 06 '12 at 15:07
  • `puts` should work. And you can try something like `kpi_poller.nonsense` to watch what happens when you try to invoke a method that doesn't exist. The problem is likely in `do_launch`. – Rob Davis Jun 06 '12 at 15:10
  • Also, I am not sure why the console changes prompts to ?> or >> does that mean I am doing something incorrectly? – Genadinik Jun 06 '12 at 15:13
  • don't add `;` at the end and it will not print you `?>` (continuation) – Victor Moroz Jun 06 '12 at 15:14
  • Also, I got this error: >> kpi_poller.nonsense NoMethodError: undefined method `nonsense' for nil:NilClass – Genadinik Jun 06 '12 at 15:15

1 Answers1

1

Try this:

module App
  module Tools
    module Pollers
      class Kpi
        attr_accessor :kpii
        def initialize(val=1)
          @kpii = val*2
        end
      end
    end
  end
end

kpi_poller = App::Tools::Pollers::Kpi.new(3)
puts kpi_poller.kpii  # 6
Anil
  • 3,899
  • 1
  • 20
  • 28