ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:90913] [Ruby trunk Misc#15514] Add documentation for implicit array decomposition
       [not found] <redmine.issue-15514.20190107102651@ruby-lang.org>
@ 2019-01-07 10:26 ` mail
  2019-01-07 11:10 ` [ruby-core:90914] " shevegen
  2019-01-10 16:43 ` [ruby-core:91004] " lisa.ugray
  2 siblings, 0 replies; 3+ messages in thread
From: mail @ 2019-01-07 10:26 UTC (permalink / raw)
  To: ruby-core

Issue #15514 has been reported by sos4nt (Stefan Schüßler).

----------------------------------------
Misc #15514: Add documentation for implicit array decomposition
https://bugs.ruby-lang.org/issues/15514

* Author: sos4nt (Stefan Schüßler)
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
The documentation for [Array Decomposition](http://ruby-doc.org/core/doc/syntax/assignment_rdoc.html#label-Array+Decomposition) says: _"[...] you can decompose an Array during assignment using parenthesis [sic]"_ and gives an example:

```ruby
(a, b) = [1, 2]

p a: a, b: b # prints {:a=>1, :b=>2}
```

But – as we all know – it's also possible _without_ parentheses, i.e.

```ruby
a, b = [1, 2]

p a: a , b: b #=> {:a=>1, :b=>2}
```

This also applies to block arguments when yielding multiple values vs. yielding a single array:

```ruby
def foo
  yield 1, 2
end

def bar
  yield [1, 2]
end

foo { |a, b| p a: a, b: b }
#=> {:a=>1, :b=>2}

bar { |a, b| p a: a, b: b }
#=> {:a=>1, :b=>2}
```

In both cases, parentheses are optional.

This implicit array decomposition could be quite surprising for newcomers. The documentation should cover it.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:90914] [Ruby trunk Misc#15514] Add documentation for implicit array decomposition
       [not found] <redmine.issue-15514.20190107102651@ruby-lang.org>
  2019-01-07 10:26 ` [ruby-core:90913] [Ruby trunk Misc#15514] Add documentation for implicit array decomposition mail
@ 2019-01-07 11:10 ` shevegen
  2019-01-10 16:43 ` [ruby-core:91004] " lisa.ugray
  2 siblings, 0 replies; 3+ messages in thread
From: shevegen @ 2019-01-07 11:10 UTC (permalink / raw)
  To: ruby-core

Issue #15514 has been updated by shevegen (Robert A. Heiler).


Agreed.

----------------------------------------
Misc #15514: Add documentation for implicit array decomposition
https://bugs.ruby-lang.org/issues/15514#change-76105

* Author: sos4nt (Stefan Schüßler)
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
The documentation for [Array Decomposition](http://ruby-doc.org/core/doc/syntax/assignment_rdoc.html#label-Array+Decomposition) says: _"[...] you can decompose an Array during assignment using parenthesis [sic]"_ and gives an example:

```ruby
(a, b) = [1, 2]

p a: a, b: b # prints {:a=>1, :b=>2}
```

But – as we all know – it's also possible _without_ parentheses, i.e.

```ruby
a, b = [1, 2]

p a: a , b: b #=> {:a=>1, :b=>2}
```

This also applies to block arguments when yielding multiple values vs. yielding a single array:

```ruby
def foo
  yield 1, 2
end

def bar
  yield [1, 2]
end

foo { |a, b| p a: a, b: b }
#=> {:a=>1, :b=>2}

bar { |a, b| p a: a, b: b }
#=> {:a=>1, :b=>2}
```

In both cases, parentheses are optional.

This implicit array decomposition could be quite surprising for newcomers. The documentation should cover it.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-core:91004] [Ruby trunk Misc#15514] Add documentation for implicit array decomposition
       [not found] <redmine.issue-15514.20190107102651@ruby-lang.org>
  2019-01-07 10:26 ` [ruby-core:90913] [Ruby trunk Misc#15514] Add documentation for implicit array decomposition mail
  2019-01-07 11:10 ` [ruby-core:90914] " shevegen
@ 2019-01-10 16:43 ` lisa.ugray
  2 siblings, 0 replies; 3+ messages in thread
From: lisa.ugray @ 2019-01-10 16:43 UTC (permalink / raw)
  To: ruby-core

Issue #15514 has been updated by lugray (Lisa Ugray).


If that's covered (and I agree it should be) it's also worth showing a case where they are not optional:
```
def baz
  yield [1, 2], 3
end

baz { |a, b, c| p a: a, b: b, c: c }
#=> {:a=>[1, 2], :b=>3, :c=>nil}

baz { |(a, b), c| p a: a, b: b, c: c }
#=> {:a=>1, :b=>2, :c=>3}
```


----------------------------------------
Misc #15514: Add documentation for implicit array decomposition
https://bugs.ruby-lang.org/issues/15514#change-76225

* Author: sos4nt (Stefan Schüßler)
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
The documentation for [Array Decomposition](http://ruby-doc.org/core/doc/syntax/assignment_rdoc.html#label-Array+Decomposition) says: _"[...] you can decompose an Array during assignment using parenthesis [sic]"_ and gives an example:

```ruby
(a, b) = [1, 2]

p a: a, b: b # prints {:a=>1, :b=>2}
```

But – as we all know – it's also possible _without_ parentheses, i.e.

```ruby
a, b = [1, 2]

p a: a , b: b #=> {:a=>1, :b=>2}
```

This also applies to block arguments when yielding multiple values vs. yielding a single array:

```ruby
def foo
  yield 1, 2
end

def bar
  yield [1, 2]
end

foo { |a, b| p a: a, b: b }
#=> {:a=>1, :b=>2}

bar { |a, b| p a: a, b: b }
#=> {:a=>1, :b=>2}
```

In both cases, parentheses are optional.

This implicit array decomposition could be quite surprising for newcomers. The documentation should cover it.



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-10 16:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15514.20190107102651@ruby-lang.org>
2019-01-07 10:26 ` [ruby-core:90913] [Ruby trunk Misc#15514] Add documentation for implicit array decomposition mail
2019-01-07 11:10 ` [ruby-core:90914] " shevegen
2019-01-10 16:43 ` [ruby-core:91004] " lisa.ugray

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).