Variables

Hi

How do I correctly write:
  puts a,b=3,4 # in 1 line (output should be like puts a,b)

Opti


The big question is: why? What's wrong with using two lines?

For the record, each of `
a
`, `
b=3
`, and `
4
` are valid statements in Ruby, so there'd be no way to tell the parser (or
a human reading your code) that you're doing a single multi-assignment
rather than listing of three statements as parameters. It took me quite a
while to understand what you were even asking here.

Cheers

···

On 5 November 2016 at 07:37, Die Optimisten <inform@die-optimisten.net> wrote:

Hi

How do I correctly write:
puts a,b=3,4 # in 1 line (output should be like puts a,b)

Opti

--
  Matthew Kerwin
  http://matthew.kerwin.net.au/

Hi
nothing, but now I understand, that it could have another meaning (as 3 statements)
bad, that puts((a,b)=3,4) isn't working!

Opti

···

On 2016-11-04 23:10, Matthew Kerwin wrote:

The big question is: why? What's wrong with using two lines?

puts(*(a,b=3,4))

But PLEASE just use 2 (or even 3) lines.

-Rob

···

On Fri, Nov 4, 2016, 18:53 Die Optimisten <inform@die-optimisten.net> wrote:

On 2016-11-04 23:10, Matthew Kerwin wrote:

The big question is: why? What's wrong with using two lines?

Hi
nothing, but now I understand, that it could have another meaning (as 3
statements)
bad, that puts((a,b)=3,4) isn't working!

Opti

puts(*(a,b=3,4))

puts((a,b=3,4))

But PLEASE just use 2 (or even 3) lines.

Yeah, it's silly.

Cheers

robert

···

On Sat, Nov 5, 2016 at 5:49 AM, Rob Biedenharn <rob.biedenharn@gmail.com> wrote:

--
[guy, jim, charlie].each {|him| remember.him do |as, often| as.you_can
- without end}
http://blog.rubybestpractices.com/

puts(*(a,b=3,4))

yeah!

Yeah, it's silly.

Exceeding the limits of the interpreter :slight_smile:
puts [1,2] works...

Opti

···

On 2016-11-05 16:30, Robert Klemme wrote:

On Sat, Nov 5, 2016 at 5:49 AM, Rob Biedenharn <rob.biedenharn@gmail.com> wrote:

IMO: No,
it comes from the habit of leaving out parenthesis and wrong expectations:

puts(a,b=3,4)

does NOT leave room for uncertainty, you would anyone expect a,b=3,4 to be regarded as a single item?

cheers
ralf

···

On 11/05/2016 10:43 PM, Die Optimisten wrote:

On 2016-11-05 16:30, Robert Klemme wrote:

On Sat, Nov 5, 2016 at 5:49 AM, Rob Biedenharn <rob.biedenharn@gmail.com> wrote:

puts(*(a,b=3,4))

yeah!

Yeah, it's silly.

Exceeding the limits of the interpreter :slight_smile: