Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8202693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:16:38+00:00 2026-06-07T07:16:38+00:00

I am using Ruby console. I start it by using Rails console and then

  • 0

I am using Ruby console. I start it by using Rails console and then do require ‘path to my file’ which works fine.

The file looks like this:

module App
  module Tools
    module Pollers
      class Kpi
        attr_reader :start_time,:stop_time

        def initialize(start_time,stop_time)
          @start_time = start_time
          @stop_time = stop_time
        end

        def create_social_audiences
        ....

So what I do is declare the stop and start time like this in the console

var end_date = new Date(2012, 7, 1);
var start  = new Date(2012, 5, 1);

and then I try to call .new on this file and get this error

>> kpi = App::Tools::Pollers::Kpi.new
ArgumentError: wrong number of arguments (0 for 2)
    from (irb):7:in `initialize'
    from (irb):7:in `new'
    from (irb):7
>> 

but the weird part is that if I do this command which attempts to pass the variables it works:

>> kpi = App::Tools::Pollers::Kpi.new(start , end_date)
=> #<App::Tools::Pollers::Kpi:0x11489e198 @start_time=nil, @stop_time=nil>

but then when I try to do set the varialbes to anything other than nil I get errors that initialize is a private method:

?> kpi.initialize(start, end_date)
NoMethodError: private method `initialize' called for #<App::Tools::Pollers::Kpi:0x11489e198>
    from (irb):15

Any thoughts on what might be happening wrong here?

Thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:16:40+00:00Added an answer on June 7, 2026 at 7:16 am

    You should not call the class initializer after the class has been instantiated (and you cannot from outside of the class itself, given that it has private visibility).

    The following does not work because you have an initializer with two parameters, therefore you also must pass those:

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

    This works because the initializer is called when the class is being constructed (the initialize method is always invoked when you create a new instance using new):

    kpi = App::Tools::Pollers::Kpi.new(start , end_date)
    

    Finally, the following does not work (no matter what values start/end_date hold) because, as I explained earlier, the initializer of a class is private in ruby:

     kpi.initialize(start, end_date) # Breaks!
    

    If you want to modify these variables after constructing the class, create a method for that:

    def initialize(start, end)
        set_time(start_end)
    end
    
    def set_time(start, end)
        @start_time = start
        @end_time = end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Ruby on Rails 3.0.9 and I would like to seed the
I am using ruby 1.8.7 and rails 2.3.5 and I am getting this weird
I am using Ruby on Rails 3.0.10 and I would like to subtract two
Using Ruby, I'm trying to parse some documentation in which I need to split
Using Ruby 1.8.6 & Rails 1.2. Models: Job , JobExtraStop : class JobExtraStop <
Using Ruby on Rails. I'm trying to sort a query by number (saved as
using Ruby on Rails 2.3.2, since I already created Scaffold for Story, so instead
Using Ruby 1.8.7-p358, Rails 3.0.12, gem responder, gem simple-form; jquery_ujs.js I have a form
I'm using Ruby on Rails with jQuery and trying to do the following: <%=
I'm frequently starting up rails console or rails server or using other command line

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.