From: Tom Werner Date: 2007-08-07T08:55:26+09:00 Subject: Re: Very weird behaviour of Ruby 1.8.6 with multi-line parenthesis expressions Michael Hollins wrote: > > Are there any interesting uses of > > + x > > as a statement on its own, or is it likely that > it's a programmer error 99 times out 100? If the latter, perhaps it's > worth > the ruby interpreter emitting a warning when it sees such constructs, > much > like the warning you get when you don't use parantheses around > argument lists > in certain situations. > > I'm happy to be told that there are valid uses of "+ x". I'm still > learning something > new about ruby every day. > > cheers, > mick > > I've seen it used in DSLs (domain specific languages) built with ruby. It can be defined on your own classes like so: class Foo def initialize(x) @x = x end def +@ @x.reverse end end +Foo.new('foo') # => "oof" I don't think I've ever used it in any of my code, but that doesn't mean there aren't legitimate uses for it. Anyone else used unary plus for something useful? Tom