Genadinik
Genadinik

Reputation: 18629

Ruby on Rails - how to invoke a ruby class from console?

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!

Upvotes: 0

Views: 1891

Answers (1)

Anil
Anil

Reputation: 3919

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

Upvotes: 1

Related Questions