# Calling a setter method in self (without self.)

**URL:** <https://www.ruby-forum.com/t/calling-a-setter-method-in-self-without-self/88598>\
**Category:** Ruby\
**Created:** [March 12, 2007, 11:15pm UTC](https://www.ruby-forum.com/t/calling-a-setter-method-in-self-without-self/88598 "2007-03-12T23:15:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tapio\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6f9a4e/32.png) [@Tapio\_K](https://www.ruby-forum.com/u/Tapio_K)\
**Post date:** [March 12, 2007, 11:15pm UTC](https://www.ruby-forum.com/t/calling-a-setter-method-in-self-without-self/88598/1 "2007-03-12T23:15:58Z")

</div>

Hi

I’m writing a code where it would be desirable to be able to call setter  
methods in self without having to specify self explicitly. Like:  
x = 0 # calls self.x=, does not assign to a local variable

In Ruby 1.6 this was impossible. Is this still the case in 1.8 and 1.9?  
I believe it is, but would like to be sure.

Thanks!

---

<div class="post-metadata">

**Author:** ![Tapio\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/6f9a4e/32.png) [@Tapio\_K](https://www.ruby-forum.com/u/Tapio_K)\
**Post date:** [March 12, 2007, 11:31pm UTC](https://www.ruby-forum.com/t/calling-a-setter-method-in-self-without-self/88598/2 "2007-03-12T23:31:07Z")

</div>

On Tue, 13 Mar 2007, Tapio K. wrote:

> –  
> Tapio

a work around…

harp:~ \> cat a.rb  
require ‘rubygems’  
require ‘attributes’

attribute :x

x 42

p x

harp:~ \> ruby a.rb  
42

cheers.

-a
