[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

`attr_accessor` and predicate/question mark methods.

Tim Becker

11/29/2006 3:04:00 PM

Hi,
I just stumbled across this weird behaviour and I'm puzzled that I've
not noticed it before. If I use `attr_accessor` to define a predicate
method, i.e. one ending in a question mark, the following happens:

class Test
attr_accessor :weird?
end

t = new Test
t.weird? => nil
t.weird?=true => SyntaxError: compile error

Which is only mildly confusing, considering it's implied somewhere in
the pickaxe book that bangs or question marks are only allowed at the
end of method names. In fact:

class Test2
def weird?= val
end
end

fails with `SyntaxError` as well. What's baffling me is that
`attr_accessor`'s is capable of adding the method `weird?=`, which
can be verified calling `methods`:

t.methods => [... "weird?=" ...]

The method is there, only calling it causes the `SyntaxError`... Am I
missing something entirely obvious here?
-tim

10 Answers

dblack

11/29/2006 3:22:00 PM

0

Tim Becker

11/29/2006 3:35:00 PM

0

> What version of Ruby are you using?
A rather oldish 1.8.2, I just realized:

> ruby -version
ruby 1.8.2 (2004-12-25) [i686-linux]

So this is in fact most likely a fixed bug. Sorry for not googling
this, but try searching for ?=

Good to know I'm not insane, just lazy. I've checked 1.8.5 on this
setup, and it worked.

Thanks!
-tim

rb(main):001:0> class Test
irb(main):002:1> attr_accessor :weird?
irb(main):003:1> end
=> nil
irb(main):004:0> exit

>
>
> David
>
> --
> David A. Black | dblack@wobblini.net
> Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3]
> DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4]
> [1] http://www.manning... | [3] http://www.rubypoweran...
> [2] http://dablog.r... | [4] http://www.rubyc...
>
>

Daniel Berger

11/29/2006 3:42:00 PM

0

Tim Becker wrote:
> Hi,
> I just stumbled across this weird behaviour and I'm puzzled that I've
> not noticed it before. If I use `attr_accessor` to define a predicate
> method, i.e. one ending in a question mark, the following happens:
>
> class Test
> attr_accessor :weird?
> end
>
> t = new Test
> t.weird? => nil
> t.weird?=true => SyntaxError: compile error
>
> Which is only mildly confusing, considering it's implied somewhere in
> the pickaxe book that bangs or question marks are only allowed at the
> end of method names. In fact:
>
> class Test2
> def weird?= val
> end
> end
>
> fails with `SyntaxError` as well. What's baffling me is that
> `attr_accessor`'s is capable of adding the method `weird?=`, which
> can be verified calling `methods`:
>
> t.methods => [... "weird?=" ...]
>
> The method is there, only calling it causes the `SyntaxError`... Am I
> missing something entirely obvious here?
> -tim

This was a bug that was "fixed" in a 1.8.5. In 1.8.5 trying to do
'attr_accessor :weird?' raises a NameError.

I had voted that doing 'attr_accessor :weird?' should create a "weird?"
and "weird=" method, but I was shot down by programmers who were more
interested in being correct than useful (am I bitter? nah). See
ruby-core:5796 and following for more information.

Regards,

Dan

PS - My apologies if this is a double post - Google server flaked out.

Rob Sanheim

11/29/2006 9:48:00 PM

0

On 11/29/06, Daniel Berger <djberg96@gmail.com> wrote:
> Tim Becker wrote:
> > Hi,
> > I just stumbled across this weird behaviour and I'm puzzled that I've
> > not noticed it before. If I use `attr_accessor` to define a predicate
> > method, i.e. one ending in a question mark, the following happens:
> >
> > class Test
> > attr_accessor :weird?
> > end
> >
> > t = new Test
> > t.weird? => nil
> > t.weird?=true => SyntaxError: compile error
> >
> > Which is only mildly confusing, considering it's implied somewhere in
> > the pickaxe book that bangs or question marks are only allowed at the
> > end of method names. In fact:
> >
> > class Test2
> > def weird?= val
> > end
> > end
> >
> > fails with `SyntaxError` as well. What's baffling me is that
> > `attr_accessor`'s is capable of adding the method `weird?=`, which
> > can be verified calling `methods`:
> >
> > t.methods => [... "weird?=" ...]
> >
> > The method is there, only calling it causes the `SyntaxError`... Am I
> > missing something entirely obvious here?
> > -tim
>
> This was a bug that was "fixed" in a 1.8.5. In 1.8.5 trying to do
> 'attr_accessor :weird?' raises a NameError.
>
> I had voted that doing 'attr_accessor :weird?' should create a "weird?"
> and "weird=" method, but I was shot down by programmers who were more
> interested in being correct than useful (am I bitter? nah). See
> ruby-core:5796 and following for more information.
>
> Regards,
>
> Dan
>
> PS - My apologies if this is a double post - Google server flaked out.

Hmm, I just went through the thread on ruby-core, and I didn't see
anyone really shoot you down. There was some debate, but the last
thing Matz said was "I'm not sure", so maybe its still an option? Or
was there a later thread that officially shot it down?

- Rob
--
http://www.robs...
http://www.seekin...
http://www.a...

Daniel Berger

11/29/2006 10:07:00 PM

0

Rob Sanheim wrote:

<snip>

> > This was a bug that was "fixed" in a 1.8.5. In 1.8.5 trying to do
> > 'attr_accessor :weird?' raises a NameError.
> >
> > I had voted that doing 'attr_accessor :weird?' should create a "weird?"
> > and "weird=" method, but I was shot down by programmers who were more
> > interested in being correct than useful (am I bitter? nah). See
> > ruby-core:5796 and following for more information.

<snip>

> Hmm, I just went through the thread on ruby-core, and I didn't see
> anyone really shoot you down. There was some debate, but the last
> thing Matz said was "I'm not sure", so maybe its still an option? Or
> was there a later thread that officially shot it down?

The current 1.8.5 behavior shows which direction Matz chose so, yes, I
was shot down (implicitly rather than explicitly - another cause for
annoyance, actually). There may have been followup in ruby-devel, but
I don't follow that list (since it's mostly Japanese). I doubt there's
any going back now, but you're certainly free to try.

Regards,

Dan

Butch

11/17/2010 6:35:00 PM

0

On Nov 17, 11:12 am, Pinsgonewild <pinplay...@gmail.com> wrote:
> I have attended the show for the past 8 years or so. It’s just
> frustrating to have a show like Allentown cancelled because one person
> decides they are done.
>
> If you no longer want to be the promoter for a show that you have run
> for 17 years and you have been doing it for the love of the game, it
> seems to me that you could have reached out to the many people you
> have worked with or established contacts with over the years to offer
> a smooth transition to a new promoter behind the scenes.
>
> Posting that the show is done because you are does not seem like the
> professional thing to do in support of the hobby. As far as
> profitability of the show I am making an assumption that can only be
> substantiated either way if they were willing to open their books.
>
> Don

Give me a break
Brian & Denise have done as much for the hobby by running the show for
the past 17 years as anyone else. They have every right to say
"enough" without anyone criticizing their decision. I have worked the
show since it started at Merchants Square. Brian gave me and the other
staff the courtesy of a heads up on Sunday night explaining his
reasons. I agreed with him 100%. During that time I can't remember
anyone coming up to Brian or Denise volunteering to take over once
they decided the time has come. Probably because of the time and
effort needed to run a sucessful show.
As far as opening up the books. It's no one's business except theirs.

Butch Horwath

pinrayhji

11/17/2010 6:45:00 PM

0

On Nov 17, 1:35 pm, Butch <Butch55...@aol.com> wrote:
> On Nov 17, 11:12 am, Pinsgonewild <pinplay...@gmail.com> wrote:
>
>
>
>
>
> > I have attended the show for the past 8 years or so. It’s just
> > frustrating to have a show like Allentown cancelled because one person
> > decides they are done.
>
> > If you no longer want to be the promoter for a show that you have run
> > for 17 years and you have been doing it for the love of the game, it
> > seems to me that you could have reached out to the many people you
> > have worked with or established contacts with over the years to offer
> > a smooth transition to a new promoter behind the scenes.
>
> > Posting that the show is done because you are does not seem like the
> > professional thing to do in support of the hobby. As far as
> > profitability of the show I am making an assumption that can only be
> > substantiated either way if they were willing to open their books.
>
> > Don
>
> Give me a break
> Brian & Denise have done as much for the hobby by running the show for
> the past 17 years as anyone else. They have every right to say
> "enough" without anyone criticizing their decision. I have worked the
> show since it started at Merchants Square. Brian gave me and the other
> staff  the courtesy of a heads up on Sunday night explaining his
> reasons. I agreed with him 100%. During that time I can't remember
> anyone coming up to Brian or Denise volunteering to take over once
> they decided the time has come. Probably because of the time and
> effort needed to run a sucessful show.
> As far as opening up the books. It's no one's business except theirs.
>
> Butch Horwath- Hide quoted text -
>
> - Show quoted text -

Butch is right on, and I have been one of his Allentown Show volunteer
colleagues for the past 13 or 14 shows. You put this succinctly,
Butch, and I have nothing to add (although it is damned tempting).
Harry Irvin
Macungie, PA

mikepin

11/17/2010 6:48:00 PM

0

I asked Brian last year if he was interested in selling the
show.... mike pacak

Pinsgonewild

11/17/2010 6:58:00 PM

0

On Nov 17, 1:22 pm, (J.G. Wentworth) cash...@cashnow.com wrote:
> In article <930d5e24-7609-42cd-bf68-2417a4a20...@y23g2000yqd.googlegroups..com>,
> Pinsgonewild says...
>
>
>
>
>
>
>
> >I have attended the show for the past 8 years or so. It=92s just
> >frustrating to have a show like Allentown cancelled because one person
> >decides they are done.
>
> >If you no longer want to be the promoter for a show that you have run
> >for 17 years and you have been doing it for the love of the game, it
> >seems to me that you could have reached out to the many people you
> >have worked with or established contacts with over the years to offer
> >a smooth transition to a new promoter behind the scenes.
>
> >Posting that the show is done because you are does not seem like the
> >professional thing to do in support of the hobby. As far as
> >profitability of the show I am making an assumption that can only be
> >substantiated either way if they were willing to open their books.
>
> >Don
>
> I guess Brian and Denise should have consulted with you about the proper way to
> bow out of something that has consumed their lives for 17 years.
>
> And, they should have flown out to your house to show you their financial
> records.
>
> You are an idiot.- Hide quoted text -
>
> - Show quoted text -

Is it necessary to resort to name calling. I'm only voicing my
opinion.
.
Don

ldnayman

11/17/2010 7:51:00 PM

0

On Nov 17, 1:57 pm, Pinsgonewild <pinplay...@gmail.com> wrote:
>
> Is it necessary to resort to name calling. I'm only voicing my
> opinion.
> .
> Don- Hide quoted text -
>
> - Show quoted text -

Your opinion sucks.