[#78633] ruby/spec needs help from CRuby committers — Benoit Daloze <eregontp@...>
Currently, ruby/spec is maintained mostly by individuals and enjoys the
13 messages
2016/12/13
[#78963] Re: ruby/spec needs help from CRuby committers
— Urabe Shyouhei <shyouhei@...>
2017/01/04
I did ask attendees of last developer meeting to join this
[#78642] Re: ruby/spec needs help from CRuby committers
— Eric Wong <normalperson@...>
2016/12/14
Benoit Daloze <eregontp@gmail.com> wrote:
[ruby-core:78454] [Ruby trunk Feature#12995] Conditional expression taking a receiver outside the condition
From:
herwin@...
Date:
2016-12-01 12:15:11 UTC
List:
ruby-core #78454
Issue #12995 has been updated by Herwin Quarantainenet.
You can do that with #tap. A very stupid example:
```ruby
array = [true]
res = array.to_a.tap do |obj|
if obj[0]
obj.replace([['true', :val]])
else
obj.replace([['false', :val]])
end
end.to_a.to_h
p res
```
Results in:
```ruby
{"true"=>:val}
```
----------------------------------------
Feature #12995: Conditional expression taking a receiver outside the condition
https://bugs.ruby-lang.org/issues/12995#change-61825
* Author: Tsuyoshi Sawada
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Since a conditional expression has a return value, we can continue a method chain after a conditional expression like this:
```ruby
if hoge
foo1.foo2.foo3
else
bar1.bar2
end
.baz1.baz2.baz3.baz4
```
```ruby
case hoge
when hoge1
foo1.foo2.foo3
when hoge2
bar1.bar2
end
.baz1.baz2.baz3.baz4
```
It is convenient if we can have a condition after or in the middle of a chain. I would like to do this:
```ruby
baz1.baz2.baz3.baz4.
if hoge
foo1.foo2.foo3
else
bar1.bar2
end
```
```ruby
baz1.baz2.baz3.baz4
if hoge
.foo1.foo2.foo3
else
.bar1.bar2
end
```
```ruby
baz1.baz2.baz3.baz4.
case hoge
when hoge1
foo1.foo2.foo3
when hoge2
bar1.bar2
end
```
```ruby
baz1.baz2.baz3.baz4
case hoge
when hoge1
.foo1.foo2.foo3
when hoge2
.bar1.bar2
end
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>