# When are attr\_reader type methods called?

**URL:** <https://rubytalk.org/t/when-are-attr-reader-type-methods-called/23475>\
**Category:** ruby-talk\
**Created:** [21 December 2005 04:48 UTC](https://rubytalk.org/t/when-are-attr-reader-type-methods-called/23475 "2005-12-21T04:48:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Sheppard](https://avatars.discourse-cdn.com/v4/letter/d/db5fbb/32.png) [@Daniel\_Sheppard](https://rubytalk.org/u/Daniel_Sheppard)\
**Post date:** [21 December 2005 04:48 UTC](https://rubytalk.org/t/when-are-attr-reader-type-methods-called/23475/1 "2005-12-21T04:48:26Z")

</div>

class A  
&nbsp;&nbsp;call\_this ("hello world")  
&nbsp;&nbsp;def call\_this(arg)  
&nbsp;&nbsp;&nbsp;&nbsp;p arg  
&nbsp;&nbsp;end  
end

gives me

NoMethodError: undefined method `call\_this' for A:Class  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from (irb):3

So you're obviously doing something more than just what you posted -  
what's in the ...?

class A  
&nbsp;&nbsp;&nbsp;attr\_reader :monkeys  
end

is roughly equivalent to writing:

A = Class.new  
A.define\_method :monkeys {  
&nbsp;&nbsp;instance\_variable\_get(:@monkeys)  
}

Is that what you're asking? Try posting a short piece of code with  
actual and expected outputs.

> **···**
>
> #####################################################################################  
> This email has been scanned by MailMarshal, an email content filter.  
> #####################################################################################  
> #####################################################################################  
> This e-mail message has been scanned for Viruses and Content and cleared  
> by NetIQ MailMarshal  
> #####################################################################################
