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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:48:17+00:00 2026-06-01T23:48:17+00:00

I found an interesting problem: http://rubeque.com/problems/fixing-bad-code-the-wrong-way/solutions Generally we have a simple class (notice that

  • 0

I found an interesting problem: http://rubeque.com/problems/fixing-bad-code-the-wrong-way/solutions

Generally we have a simple class (notice that we don’t have attr_accessor here):

class Foo
  def itnialize(name)
    self.foo = name
  end

  def set_bar 
    self.bar = 'it will fail..'
  end
end

I thought that ruby will raise no method error when I call Foo.new but it passes without any problems. The code will fail when I try Foo.new.bar

How is it possible and how to access Foo.new.foo 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-06-01T23:48:19+00:00Added an answer on June 1, 2026 at 11:48 pm

    You have a typo and have miss-spelt initialize as itnialize so it won’t be being called – so no error.

    It looks like you’re trying to create an instance variable – to do so you need, somewhere, to define it with the @ prefix. So you might do:

    def initialize(name)
      @foo = name
    end
    

    which would then mean you are able to access @foo inside the class.

    self.foo can only ever refer to a method foo, so you need to define that method if you want to call it, either explicitly or by using one of the attr variants.

    However, in this case, you could just do

    def set_bar
      @bar = 'it will succeed!'
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found this interesting site, that helps me understand derivatives, http://www.numberempire.com/derivatives.php , It seems
I found this very interesting: http://matthewjamestaylor.com/blog/ultimate-3-column-holy-grail-pixels.htm He avoid using horizontal margin and paddings to
I found a pretty interesting problem installing ruby gems bluehat@Matapan:~/code/Amacron$ rails server --debugger =>
I have been told that Singletons are hard to test. http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/ http://misko.hevery.com/code-reviewers-guide/flaw-brittle-global-state-singletons/ I have
on http://www.w3.org/TR/css3-selectors/#negation I found interesting selectors html|*:not(:link):not(:visited) does anybody knows what | means.
I have found an interesting issue in windows which allows me to cause the
I have found some interesting behavior and do not know why or how to
I was looking through a code tutorial just now, and found something interesting --
Here's an interesting problem: I have some jQuery that looks like this: $(document).ready(function() {
I've been reading this http://msdn.microsoft.com/en-us/magazine/cc163681.aspx and found the part about defining abstract base classes

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.