From: Doug Glidden <41mortimer@...> Date: 2008-08-28T00:28:39+09:00 Subject: Re: assert_raise question Brian Candler wrote: >> def test_raise >> assert_raise ArgumentError {raise ArgumentError.new("basic argument issue")} >> end >> >> Now there's suddenly an Exception: undefined method 'ArgumentError'... >> I was more than a little surprised to discover that the parens make a >> difference here? Can anyone explain to me _why_ there's a difference? > > I believe that x y z is parsed as x(y(z)): > > irb(main):013:0> puts ArgumentError > ArgumentError > => nil > irb(main):014:0> puts ArgumentError 123 > (irb):14: warning: parenthesize argument(s) for future version > NoMethodError: undefined method `ArgumentError' for main:Object > from (irb):14 > from :0 > irb(main):015:0> puts ArgumentError(123) > NoMethodError: undefined method `ArgumentError' for main:Object > from (irb):15 > from :0 > irb(main):016:0> > > and x y {block} is parsed as x(y() {block}), i.e. y is forced to be a > method > call as that's the only meaningful thing next to a block. > [snip] Well, now that you explained it, it makes perfect sense! Thanks. I guess in the future I'll double-check a little more carefully that my code is doing what I expect when I leave out parens. Doug -- Posted via http://www.ruby-forum.com/.