ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:71650] [Ruby trunk - Feature #11734] [Open] Improved ternary operator
       [not found] <redmine.issue-11734.20151124143335@ruby-lang.org>
@ 2015-11-24 14:33 ` bregey
  2015-11-24 15:10 ` [ruby-core:71651] [Ruby trunk - Feature #11734] " hanmac
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: bregey @ 2015-11-24 14:33 UTC (permalink / raw)
  To: ruby-core

Issue #11734 has been reported by Yurko Bregey.

----------------------------------------
Feature #11734: Improved ternary operator
https://bugs.ruby-lang.org/issues/11734

* Author: Yurko Bregey
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
In ternary operator it would be nice to be able to pass expression result from *condition*  into *value_if_true/value_if_false* in such way:

`some_long_expression ? &.to_s : 'foobar'`
where `&` refers to `some_long_expression`

Instead of doing:
`some_long_expression ? some_long_expression.to_s : 'foobar'`

or:
`result = some_very_very_long_expression
result ? result.to_s : 'foobar'`



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

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

* [ruby-core:71651] [Ruby trunk - Feature #11734] Improved ternary operator
       [not found] <redmine.issue-11734.20151124143335@ruby-lang.org>
  2015-11-24 14:33 ` [ruby-core:71650] [Ruby trunk - Feature #11734] [Open] Improved ternary operator bregey
@ 2015-11-24 15:10 ` hanmac
  2015-11-24 20:28 ` [ruby-core:71662] " 6ftdan
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: hanmac @ 2015-11-24 15:10 UTC (permalink / raw)
  To: ruby-core

Issue #11734 has been updated by Hans Mackowiak.


why not:

```ruby
(x = some_long_expression) ? x.to_s : 'foobar'
```

----------------------------------------
Feature #11734: Improved ternary operator
https://bugs.ruby-lang.org/issues/11734#change-55056

* Author: Yurko Bregey
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
In ternary operator it would be nice to be able to pass expression result from *condition*  into *value_if_true/value_if_false* in such way:

`some_long_expression ? &.to_s : 'foobar'`
where `&` refers to `some_long_expression`

Instead of doing:
`some_long_expression ? some_long_expression.to_s : 'foobar'`

or:
`result = some_very_very_long_expression
result ? result.to_s : 'foobar'`



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

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

* [ruby-core:71662] [Ruby trunk - Feature #11734] Improved ternary operator
       [not found] <redmine.issue-11734.20151124143335@ruby-lang.org>
  2015-11-24 14:33 ` [ruby-core:71650] [Ruby trunk - Feature #11734] [Open] Improved ternary operator bregey
  2015-11-24 15:10 ` [ruby-core:71651] [Ruby trunk - Feature #11734] " hanmac
@ 2015-11-24 20:28 ` 6ftdan
  2015-11-25  5:10 ` [ruby-core:71677] " hanmac
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: 6ftdan @ 2015-11-24 20:28 UTC (permalink / raw)
  To: ruby-core

Issue #11734 has been updated by Daniel P. Clark.


`&` is associated more with proc.  I think `_` would be closer to the kind of thing you're looking for.

~~~ruby
some_long_expression = :baz
_ ? _.to_s : 'foobar'
# => "baz"
~~~

Although I tried in-lining it with a semicolon and found that the `_` feature only works off of the previous' lines results. So the following won't work.

~~~ruby
:baz; _ ? _.to_s : 'foobar'
# => "foobar"
~~~

And this doesn't work

~~~ruby
x = 4
:fiz ? _.to_s : 'foobar'
# => "4"
~~~

So if you don't mind putting your ternary operation on the next line you can just use `_`

----------------------------------------
Feature #11734: Improved ternary operator
https://bugs.ruby-lang.org/issues/11734#change-55065

* Author: Yurko Bregey
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
In ternary operator it would be nice to be able to pass expression result from *condition*  into *value_if_true/value_if_false* in such way:

`some_long_expression ? &.to_s : 'foobar'`
where `&` refers to `some_long_expression`

Instead of doing:
`some_long_expression ? some_long_expression.to_s : 'foobar'`

or:
`result = some_very_very_long_expression
result ? result.to_s : 'foobar'`



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

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

* [ruby-core:71677] [Ruby trunk - Feature #11734] Improved ternary operator
       [not found] <redmine.issue-11734.20151124143335@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2015-11-24 20:28 ` [ruby-core:71662] " 6ftdan
@ 2015-11-25  5:10 ` hanmac
  2015-11-25  9:34 ` [ruby-core:71679] " nobu
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: hanmac @ 2015-11-25  5:10 UTC (permalink / raw)
  To: ruby-core

Issue #11734 has been updated by Hans Mackowiak.


@Daniel: _ with previous line result is a feature of IRB and PRY not ruby itself

----------------------------------------
Feature #11734: Improved ternary operator
https://bugs.ruby-lang.org/issues/11734#change-55079

* Author: Yurko Bregey
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
In ternary operator it would be nice to be able to pass expression result from *condition*  into *value_if_true/value_if_false* in such way:

`some_long_expression ? &.to_s : 'foobar'`
where `&` refers to `some_long_expression`

Instead of doing:
`some_long_expression ? some_long_expression.to_s : 'foobar'`

or:
`result = some_very_very_long_expression
result ? result.to_s : 'foobar'`



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

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

* [ruby-core:71679] [Ruby trunk - Feature #11734] Improved ternary operator
       [not found] <redmine.issue-11734.20151124143335@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2015-11-25  5:10 ` [ruby-core:71677] " hanmac
@ 2015-11-25  9:34 ` nobu
  2015-11-25 10:06 ` [ruby-core:71680] " bregey
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: nobu @ 2015-11-25  9:34 UTC (permalink / raw)
  To: ruby-core

Issue #11734 has been updated by Nobuyoshi Nakada.


Maybe `some_long_expression&.to_s || 'foobar'` ?

----------------------------------------
Feature #11734: Improved ternary operator
https://bugs.ruby-lang.org/issues/11734#change-55080

* Author: Yurko Bregey
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
In ternary operator it would be nice to be able to pass expression result from *condition*  into *value_if_true/value_if_false* in such way:

`some_long_expression ? &.to_s : 'foobar'`
where `&` refers to `some_long_expression`

Instead of doing:
`some_long_expression ? some_long_expression.to_s : 'foobar'`

or:
`result = some_very_very_long_expression
result ? result.to_s : 'foobar'`



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

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

* [ruby-core:71680] [Ruby trunk - Feature #11734] Improved ternary operator
       [not found] <redmine.issue-11734.20151124143335@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2015-11-25  9:34 ` [ruby-core:71679] " nobu
@ 2015-11-25 10:06 ` bregey
  2015-11-25 10:23 ` [ruby-core:71681] " bregey
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: bregey @ 2015-11-25 10:06 UTC (permalink / raw)
  To: ruby-core

Issue #11734 has been updated by Yurko Bregey.


Hans Mackowiak wrote:
> why not:
> 
> ```ruby
> (x = some_long_expression) ? x.to_s : 'foobar'
> ```

think it's not good. Ruby 2.2.3p173 shows warning:

~~~
warning: found = in conditional, should be ==
~~~

----------------------------------------
Feature #11734: Improved ternary operator
https://bugs.ruby-lang.org/issues/11734#change-55081

* Author: Yurko Bregey
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
In ternary operator it would be nice to be able to pass expression result from *condition*  into *value_if_true/value_if_false* in such way:

`some_long_expression ? &.to_s : 'foobar'`
where `&` refers to `some_long_expression`

Instead of doing:
`some_long_expression ? some_long_expression.to_s : 'foobar'`

or:
`result = some_very_very_long_expression
result ? result.to_s : 'foobar'`



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

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

* [ruby-core:71681] [Ruby trunk - Feature #11734] Improved ternary operator
       [not found] <redmine.issue-11734.20151124143335@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2015-11-25 10:06 ` [ruby-core:71680] " bregey
@ 2015-11-25 10:23 ` bregey
  2015-11-25 13:00 ` [ruby-core:71683] " hanmac
  2015-12-07  7:52 ` [ruby-core:71892] [Ruby trunk - Feature #11734] [Closed] " ko1
  8 siblings, 0 replies; 9+ messages in thread
From: bregey @ 2015-11-25 10:23 UTC (permalink / raw)
  To: ruby-core

Issue #11734 has been updated by Yurko Bregey.


Nobuyoshi Nakada wrote:
> Maybe `some_long_expression&.to_s || 'foobar'` ?

@Nobuyoshi, thanx! safe navigation from 2.3 solves such tasks.

----------------------------------------
Feature #11734: Improved ternary operator
https://bugs.ruby-lang.org/issues/11734#change-55082

* Author: Yurko Bregey
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
In ternary operator it would be nice to be able to pass expression result from *condition*  into *value_if_true/value_if_false* in such way:

`some_long_expression ? &.to_s : 'foobar'`
where `&` refers to `some_long_expression`

Instead of doing:
`some_long_expression ? some_long_expression.to_s : 'foobar'`

or:
`result = some_very_very_long_expression
result ? result.to_s : 'foobar'`



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

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

* [ruby-core:71683] [Ruby trunk - Feature #11734] Improved ternary operator
       [not found] <redmine.issue-11734.20151124143335@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2015-11-25 10:23 ` [ruby-core:71681] " bregey
@ 2015-11-25 13:00 ` hanmac
  2015-12-07  7:52 ` [ruby-core:71892] [Ruby trunk - Feature #11734] [Closed] " ko1
  8 siblings, 0 replies; 9+ messages in thread
From: hanmac @ 2015-11-25 13:00 UTC (permalink / raw)
  To: ruby-core

Issue #11734 has been updated by Hans Mackowiak.


Yurko Bregey wrote:
> Hans Mackowiak wrote:
> > why not:
> > 
> > ```ruby
> > (x = some_long_expression) ? x.to_s : 'foobar'
> > ```
> 
> think it's not good. Ruby 2.2.3p173 shows warning:
> 
> ~~~
> warning: found = in conditional, should be ==
> ~~~

you might did something wrong because on "ruby 2.3.0dev (2015-11-25 trunk 52749) [x86_64-linux]" it doesn't show any warning for me

----------------------------------------
Feature #11734: Improved ternary operator
https://bugs.ruby-lang.org/issues/11734#change-55086

* Author: Yurko Bregey
* Status: Open
* Priority: Normal
* Assignee: 
----------------------------------------
In ternary operator it would be nice to be able to pass expression result from *condition*  into *value_if_true/value_if_false* in such way:

`some_long_expression ? &.to_s : 'foobar'`
where `&` refers to `some_long_expression`

Instead of doing:
`some_long_expression ? some_long_expression.to_s : 'foobar'`

or:
`result = some_very_very_long_expression
result ? result.to_s : 'foobar'`



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

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

* [ruby-core:71892] [Ruby trunk - Feature #11734] [Closed] Improved ternary operator
       [not found] <redmine.issue-11734.20151124143335@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2015-11-25 13:00 ` [ruby-core:71683] " hanmac
@ 2015-12-07  7:52 ` ko1
  8 siblings, 0 replies; 9+ messages in thread
From: ko1 @ 2015-12-07  7:52 UTC (permalink / raw)
  To: ruby-core

Issue #11734 has been updated by Koichi Sasada.

Status changed from Open to Closed

----------------------------------------
Feature #11734: Improved ternary operator
https://bugs.ruby-lang.org/issues/11734#change-55298

* Author: Yurko Bregey
* Status: Closed
* Priority: Normal
* Assignee: 
----------------------------------------
In ternary operator it would be nice to be able to pass expression result from *condition*  into *value_if_true/value_if_false* in such way:

`some_long_expression ? &.to_s : 'foobar'`
where `&` refers to `some_long_expression`

Instead of doing:
`some_long_expression ? some_long_expression.to_s : 'foobar'`

or:
`result = some_very_very_long_expression
result ? result.to_s : 'foobar'`



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

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

end of thread, other threads:[~2015-12-07  7:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-11734.20151124143335@ruby-lang.org>
2015-11-24 14:33 ` [ruby-core:71650] [Ruby trunk - Feature #11734] [Open] Improved ternary operator bregey
2015-11-24 15:10 ` [ruby-core:71651] [Ruby trunk - Feature #11734] " hanmac
2015-11-24 20:28 ` [ruby-core:71662] " 6ftdan
2015-11-25  5:10 ` [ruby-core:71677] " hanmac
2015-11-25  9:34 ` [ruby-core:71679] " nobu
2015-11-25 10:06 ` [ruby-core:71680] " bregey
2015-11-25 10:23 ` [ruby-core:71681] " bregey
2015-11-25 13:00 ` [ruby-core:71683] " hanmac
2015-12-07  7:52 ` [ruby-core:71892] [Ruby trunk - Feature #11734] [Closed] " ko1

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).