[#100689] [Ruby master Feature#17303] Make webrick to bundled gems or remove from stdlib — hsbt@...
Issue #17303 has been reported by hsbt (Hiroshi SHIBATA).
11 messages
2020/11/02
[#100852] [Ruby master Feature#17326] Add Kernel#must! to the standard library — zimmerman.jake@...
SXNzdWUgIzE3MzI2IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGpleiAoSmFrZSBaaW1tZXJtYW4pLg0K
24 messages
2020/11/14
[#100930] [Ruby master Feature#17333] Enumerable#many? — masafumi.o1988@...
Issue #17333 has been reported by okuramasafumi (Masafumi OKURA).
10 messages
2020/11/18
[#101071] [Ruby master Feature#17342] Hash#fetch_set — hunter_spawn@...
Issue #17342 has been reported by MaxLap (Maxime Lapointe).
26 messages
2020/11/25
[ruby-core:100975] [Ruby master Feature#17336] using refined: do ... end
From:
eregontp@...
Date:
2020-11-20 12:40:01 UTC
List:
ruby-core #100975
Issue #17336 has been updated by Eregon (Benoit Daloze).
How about:
```ruby
class Foo
using do
refine Array do
def flat_map!(&block)
replace(flat_map(&block))
end
end
refine String do
...
end
end
```
So let `using` take a block instead of a positional argument.
That way, it's also possible to refine multiple classes/modules at once, which is often better than multiple `using` calls (notably, such methods can use the refinements of each other and it's more concise)
----------------------------------------
Feature #17336: using refined: do ... end
https://bugs.ruby-lang.org/issues/17336#change-88638
* Author: k0kubun (Takashi Kokubun)
* Status: Open
* Priority: Normal
----------------------------------------
## Problem
When we need a monkey patch which is used only in a single file, we'd like to define a refinement and use it in the same place. The problem is that it needs deep indentation and `Module.new { ... }` which feels redundant.
```rb
class Foo
using Module.new {
refine Array do
def flat_map!(&block)
replace(flat_map(&block))
end
end
}
# ...
end
```
@tagomoris proposed an idea to reduce indentation and remove `Module.new { ... }`. This looks pretty convenient, but I want to write `do ... end`, which would make it a block of `using` here, because we almost always use `... end` for defining methods or modules.
```rb
module Kernel
def refined(mod, &block)
Module.new do
refine(mod, &block)
end
end
end
class Foo
using refined(Array) {
def flat_map!(&block)
replace(flat_map(&block))
end
}
# ...
end
```
## Proposal
How about supporting this? Because `using` currently doesn't take a block, it doesn't conflict with the existing syntax.
```rb
class Foo
using refined: Array do
def flat_map!(&block)
replace(flat_map(&block))
end
end
# ...
end
```
This syntax is based on ideas of @tagomoris and @znz .
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>