[#79440] [Ruby trunk Bug#13188] Reinitialize Ruby VM. — shyouhei@...
Issue #13188 has been updated by Shyouhei Urabe.
6 messages
2017/02/06
[#79441] Re: [Ruby trunk Bug#13188] Reinitialize Ruby VM.
— SASADA Koichi <ko1@...>
2017/02/06
On 2017/02/06 10:10, shyouhei@ruby-lang.org wrote:
[#79532] Immutable Strings vs Symbols — Daniel Ferreira <subtileos@...>
Hi,
15 messages
2017/02/15
[#79541] Re: Immutable Strings vs Symbols
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2017/02/15
Em 15-02-2017 05:05, Daniel Ferreira escreveu:
[#79543] Re: Immutable Strings vs Symbols
— Daniel Ferreira <subtileos@...>
2017/02/16
Hi Rodrigo,
[#79560] Re: Immutable Strings vs Symbols
— Rodrigo Rosenfeld Rosas <rr.rosas@...>
2017/02/16
Em 15-02-2017 22:39, Daniel Ferreira escreveu:
[ruby-core:79721] [Ruby trunk Feature#12968] Allow default value via block for Integer(), Float() and Rational()
From:
shyouhei@...
Date:
2017-02-23 08:43:22 UTC
List:
ruby-core #79721
Issue #12968 has been updated by Shyouhei Urabe.
We looked at this issue at yesterday's developer meeting.
People there argued that explicit keyword argument is much easier to read than passing a block. They say it is not obvious what the block is going to do. So if the OP is OK we would like to to merge this issue with #12732. How do you feel, Stefan?
----------------------------------------
Feature #12968: Allow default value via block for Integer(), Float() and Rational()
https://bugs.ruby-lang.org/issues/12968#change-63144
* Author: Stefan Schテシテ殕er
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
`Kernel` provides the global conversion functions `Integer()`, `Float()` and `Rational()`. Each one convert its argument to the respective type.
Parsing errors are signaled by raising a `TypeError` or an `ArgumentError`.
I often use these methods to parse numeric string values, but I find the need for a `rescue ArgumentError` block quite annoying an distracting.
I therefore request a new feature: `Integer()`, `Float()` and `Rational()` should take an _optional block_ that serves as a callback when parsing failed.
Examples:
```ruby
Integer('foo') #=> ArgumentError (just as before)
Integer('foo') { 0 } #=> 0 (same as 'foo'.to_i)
Integer('foo') { nil } #=> nil
Integer('foo') { Float::NAN } #=> NaN
```
This resembles the way `Hash#fetch` or `Hash#fetch_values` work when a block is given.
Although not used in the examples above, any arguments should be passed along to the block, i.e. `Integer('foo') { |arg, base| ... }`
--
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>