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

  • Home
  • SEARCH
  • 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 7744087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:41:16+00:00 2026-06-01T09:41:16+00:00

The data is loaded once because it takes a while to load, doesn’t change,

  • 0

The data is loaded once because it takes a while to load, doesn’t change, and is shared. This is a static class: I am not using any instances.

class Foo
  @@ data = self.load_data

  def self.load_data
    .
    . 
    .
  end

  def self.calculate
    .
    .
  end
end

This throws an error NoMethodError: undefined method 'load_data' for Foo:Class because load_data appears after the assignment.

I don’t think initialize will work because I am not using f = Foo.new. I am using it as Foo.calculate.

Is it necessary to declare load_data before calling it? Or is there a better approach?

  • 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-01T09:41:18+00:00Added an answer on June 1, 2026 at 9:41 am

    Yes Foo.load_data doesn’t exist yet at the point you call it.

    A better pattern might be to have an accessor for @@data which auto-memoizes.

    class Foo
      def self.data
        @@data ||= load_data
      end
      def data; self.class.data; end # if you need it in instances too
    
      def self.load_data
        ...
      end
    
      def self.calculate
        data.each {} # or whatever would have used @@data
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have CSV data loaded into a multidimensional array. In this way each row
Could someone tell me if this: $.ajax({ url: 'test.html', success: function(data) { alert(Data Loaded:
I have an application that loads lots of data into memory (this is because
I have to deal with a class that takes about 2-3 minutes to load.
I have a large data loaded from a pickled file. The data is a
I'm building a dynamic ExtJS form based on JSON data loaded from an ASP.NET
On one of our Java application screens, we want to display data loaded from
I'm trying to hide table view until all the data is loaded. I found
I have a DataTable that I manually created and loaded with data using C#.
I'm working on creating a grouped table view. The data is being loaded alright,

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.