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 4024762
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:45:43+00:00 2026-05-20T10:45:43+00:00

I have a feeling I’m missing something very simple here. I have a class

  • 0

I have a feeling I’m missing something very simple here. I have a class that is linked to an external service. I want to instantiate it by either calling a create method or a find method. Both methods will populate an instance variable “@node” with a hash, either by creating a node or finding it.

I have

class GenreInfluence

@@neo ||= Neography::Rest.new()
attr_accessor :node

def initialize
end

def self.create
    @node = @@neo.create_node
    self.new
end

def self.find(node_id)
    @node = @@neo.get_node(node_id)
    self.new
end

def get_hash
  @node
end

If I comment out what’s going on, I can see it’s creating the class and getting the correct hash back however:

theInstance = GenreInfluence.find(20)
theInstance.get_hash

Just returns nil. Why is the hash not being stored in the instance variable!?

  • 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-05-20T10:45:43+00:00Added an answer on May 20, 2026 at 10:45 am

    You can’t set instance variables in a non-instance (static, or class) method. Furthermore, both your methods are returning self.new, which effectively returns a new instance of the class with no instance variables set.

    How about the following, that creates a new instance of the class in the static class methods, sets the variable on that instance, and then returns it (instead of returning self.new):

    class GenreInfluence
      @@neo ||= Neography::Rest.new()
      attr_accessor :node
    
      def initialize
      end
    
      def self.create
        influence      = self.new
        influence.node = @@neo.create_node
        influence
      end
    
      def self.find(node_id)
        influence      = self.new
        influence.node = @@neo.get_node(node_id)
        influence
      end
    
      def get_hash
        @node
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the feeling that is easy to find samples, tutorials and simple examples
I have a feeling that I already know the answer to this one, but
I have a feeling that there must be client-server synchronization patterns out there. But
I have the feeling that Flash -based ( or Silverlight -based) websites are generally
I have feeling, that if one defines a method def test puts 'Hi' end
I'm aware of IDENTITY fields but I have a feeling that I couldn't use
I have the feeling that using Sitemap in ASP.NET is not conducive to CSS.
I have a feeling this is a repost but I can't seem to find
I curious to how different people solve integration of systems. I have a feeling
I'm the leader of a small web development team, and I have a feeling

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.