# How to access a attributes from the parent class?

**URL:** <https://www.ruby-forum.com/t/how-to-access-a-attributes-from-the-parent-class/96938>\
**Category:** Ruby\
**Created:** [January 25, 2006, 1:46am UTC](https://www.ruby-forum.com/t/how-to-access-a-attributes-from-the-parent-class/96938 "2006-01-25T01:46:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaatschS\_Bernd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@PaatschS\_Bernd](https://www.ruby-forum.com/u/PaatschS_Bernd)\
**Post date:** [January 25, 2006, 1:46am UTC](https://www.ruby-forum.com/t/how-to-access-a-attributes-from-the-parent-class/96938/1 "2006-01-25T01:46:08Z")

</div>

I am new to ruby and try to figure out how inheritance works.  
I don’t get the result I expect. I marked the line of code with  
“#error”.  
What do I need to do to get it to work?

```
class WacFrames
  attr_reader :wacFrameNav
  attr_reader :wacFrameDisp
  def initialize()
  	@wacFrameNav = "nav"
 	@wacFrameDisp = "disp"
  end
end

class WacSubscribers
  attr_reader :fr
  attr_reader :frame
  def initialize()
@fr = WacFrames.new()
@frame = @fr.wacFrameNav
  end
end

class WacSubProfile < WacSubscribers
  def initialize()
#some code
  end
  end
end

another = WacSubscribers.new()
puts another.fr	#works fine
puts another.frame	#works fine

test = WacSubProfile.new()
puts test.fr #error
puts test.frame	#error

```

Thanks

---

<div class="post-metadata">

**Author:** ![PaatschS\_Bernd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@PaatschS\_Bernd](https://www.ruby-forum.com/u/PaatschS_Bernd)\
**Post date:** [January 25, 2006, 3:18am UTC](https://www.ruby-forum.com/t/how-to-access-a-attributes-from-the-parent-class/96938/2 "2006-01-25T03:18:35Z")

</div>

Paatsch, Bernd wrote:

> I am new to ruby and try to figure out how inheritance works.  
> I don’t get the result I expect. I marked the line of code with  
> “#error”.  
> What do I need to do to get it to work?
> 
> ```
> class WacSubscribers
> attr_reader :fr
> attr_reader :frame
> def initialize()
> 
> ```
> 
> @fr = WacFrames.new()  
> @frame = @fr.wacFrameNav  
> end  
> end
> 
> ```
> class WacSubProfile < WacSubscribers
> def initialize()
> 
> ```
> 
> #some code  
> end  
> end  
> end

An extra ‘end’ there but I assume it is just a copy-paste error.

> ```
> another = WacSubscribers.new()
> puts another.fr	#works fine
> puts another.frame	#works fine
> 
> test = WacSubProfile.new()
> puts test.fr #error
> puts test.frame	#error
> 
> ```

This should work fine (you might have problems if you  
do not initialize the parent’s instance variables by  
calling #super but even still the methods should return  
nils).

What error is it that you get?

> Thanks

E
