# \#attr back to 1.8.6 an older behavior?

**URL:** <https://www.ruby-forum.com/t/attr-back-to-1-8-6-an-older-behavior/193799>\
**Category:** Ruby\
**Created:** [August 24, 2010, 4:24pm UTC](https://www.ruby-forum.com/t/attr-back-to-1-8-6-an-older-behavior/193799 "2010-08-24T16:24:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [August 24, 2010, 4:24pm UTC](https://www.ruby-forum.com/t/attr-back-to-1-8-6-an-older-behavior/193799/1 "2010-08-24T16:24:37Z")

</div>

What happened to dropping the optional true/false parameter from #attr  
in 1.9? About a year or so ago, the method was changed to support  
multiple symbols, and if you wanted a writer you just add one with an  
‘=’ on the end, e.g.

attr :x, :x=

That was really nice b/c it is explicit. In general “true” parameters  
are not very readable. It also made it a touch easier to override  
#attr to add options like default values (attr :x, :default=\>10).

But I was just playing around with the latest 1.9.2 release and #attr  
is back to behaving just like 1.8.6 and older. Why the move back?

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [August 26, 2010, 4:36pm UTC](https://www.ruby-forum.com/t/attr-back-to-1-8-6-an-older-behavior/193799/2 "2010-08-26T16:36:27Z")

</div>

Thomas S. wrote:

> What happened to dropping the optional true/false parameter from #attr  
> in 1.9? About a year or so ago, the method was changed to support  
> multiple symbols, and if you wanted a writer you just add one with an  
> ‘=’ on the end, e.g.
> 
> attr :x, :x=

FWIW, it looks like 1.9.1 doesn’t allow attr :x= anyway (reader  
attributes only)

irb(main):001:0\> class Foo  
irb(main):002:1\> attr :x, :x=  
irb(main):003:1\> end  
NameError: invalid attribute name `x=' from (irb):2:in`attr’  
from (irb):2:in `<class:Foo>' from (irb):1 from /usr/local/bin/irb191:12:in`’  
irb(main):004:0\> RUBY\_DESCRIPTION  
=\> “ruby 1.9.1p429 (2010-07-02 revision 28523) [x86\_64-linux]”

---

<div class="post-metadata">

**Author:** ![tcsnide](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@tcsnide](https://www.ruby-forum.com/u/tcsnide)\
**Post date:** [August 26, 2010, 6:38pm UTC](https://www.ruby-forum.com/t/attr-back-to-1-8-6-an-older-behavior/193799/3 "2010-08-26T18:38:31Z")

</div>

On Aug 26, 10:39 am, Brian C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thomas S. wrote:
> 
> > What happened to dropping the optional true/false parameter from #attr  
> > in 1.9? About a year or so ago, the method was changed to support  
> > multiple symbols, and if you wanted a writer you just add one with an  
> > ‘=’ on the end, e.g.
> 
> > attr :x, :x=
> 
> FWIW, it looks like 1.9.1 doesn’t allow attr :x= anyway (reader  
> attributes only)

I don’t really care about the ‘x=’ option either way, though I do  
think it is a nice convenience. I do think dropping the optional true/  
false option is a good thing though for three reasons. 1) true/false  
parameters are very unreadable. They give you no information  
whatsoever as to what behavior is being toggled, 2) multiple symbols  
can be given, and 3) it can be useful to override #attr to take  
options, eg.

attr :x, :default =\> 10

I have found this useful in a number of cases, and the idiom is very  
common with variants of attr too. Having to take the true/false  
parameter into account, while not a huge deal, does leave open an  
argument ambiguity, since a Hash evaluates as true.
