[#88240] [Ruby trunk Feature#14759] [PATCH] set M_ARENA_MAX for glibc malloc โ sam.saffron@...
Issue #14759 has been updated by sam.saffron (Sam Saffron).
[#88251] Re: [ruby-alerts:8236] failure alert on trunk@P895 (NG (r64134)) โ Eric Wong <normalperson@...>
ko1c-failure@atdot.net wrote:
[#88305] [Ruby trunk Bug#14968] [PATCH] io.c: make all pipes nonblocking by default โ normalperson@...
Issue #14968 has been reported by normalperson (Eric Wong).
[#88331] [Ruby trunk Feature#13618] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid โ samuel@...
Issue #13618 has been updated by ioquatix (Samuel Williams).
[#88342] [Ruby trunk Feature#14955] [PATCH] gc.c: use MADV_FREE to release most of the heap page body โ ko1@...
Issue #14955 has been updated by ko1 (Koichi Sasada).
[#88433] [Ruby trunk Feature#13618] [PATCH] auto fiber schedule for rb_wait_for_single_fd and rb_waitpid โ ko1@...
Issue #13618 has been updated by ko1 (Koichi Sasada).
ko1@atdot.net wrote:
[#88475] [Ruby trunk Misc#14937] [PATCH] thread_pthread: lazy-spawn timer-thread only on contention โ ko1@...
Issue #14937 has been updated by ko1 (Koichi Sasada).
[#88491] Re: [ruby-cvs:71466] k0kubun:r64374 (trunk): test_function.rb: skip running test โ Eric Wong <normalperson@...>
k0kubun@ruby-lang.org wrote:
I see. Please remove the test if the test is unnecessary.
Takashi Kokubun <takashikkbn@gmail.com> wrote:
[#88523] [Ruby trunk Bug#14999] ConditionVariable doesn't reacquire the Mutex if Thread#kill-ed โ eregontp@...
Issue #14999 has been updated by Eregon (Benoit Daloze).
eregontp@gmail.com wrote:
[#88549] [Ruby trunk Bug#14999] ConditionVariable doesn't reacquire the Mutex if Thread#kill-ed โ eregontp@...
Issue #14999 has been updated by Eregon (Benoit Daloze).
[#88676] [Ruby trunk Misc#15014] thread.c: use rb_hrtime_scalar for high-resolution time operations โ ko1@...
Issue #15014 has been updated by ko1 (Koichi Sasada).
ko1@atdot.net wrote:
On 2018/08/27 16:16, Eric Wong wrote:
[#88716] Re: [ruby-dev:43715] [Ruby 1.9 - Bug #595] Fiber ignores ensure clause โ Eric Wong <normalperson@...>
Koichi Sasada wrote:
[#88723] [Ruby trunk Bug#15041] [PATCH] cont.c: set th->root_fiber to current fiber at fork โ ko1@...
Issue #15041 has been updated by ko1 (Koichi Sasada).
[#88767] [Ruby trunk Bug#15050] GC after forking with fibers crashes โ ko1@...
Issue #15050 has been updated by ko1 (Koichi Sasada).
Koichi Sasada <ko1@atdot.net> wrote:
Koichi Sasada <ko1@atdot.net> wrote:
[#88774] Re: [ruby-alerts:8955] failure alert on trunk@P895 (NG (r64594)) โ Eric Wong <normalperson@...>
ko1c-failure@atdot.net wrote:
[ruby-core:88301] [Ruby trunk Feature#14869] Proposal to add Hash#===
Issue #14869 has been updated by baweaver (Brandon Weaver).
I recently got permission to repurpose the `Any` gem, which gives us this:
```
require 'any'
case {id: 1, name: 'foo', age: 42}
when {id: Any, name: /^f/, age: Any} then true
else false
end
# => true
case {id: 1, name: 'foo'}
when {id: Any, name: /^f/, age: Any} then true
else false
end
# => false
```
That should make this even more flexible.
https://github.com/baweaver/any
----------------------------------------
Feature #14869: Proposal to add Hash#===
https://bugs.ruby-lang.org/issues/14869#change-73329
* Author: osyo (manga osyo)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
## ๆฆ่ฆ
`Hash#===` ใ่ฟฝๅ ใใๆๆกใซใชใใพใใ
## ไปๆง
ใฌใทใผใใฎใญใผใฎ่ฆ็ด ใจๅผๆฐใฎใใใทใฅใฎใญใผใฎ่ฆ็ด ใ `#===` ใงๆฏ่ผใใฆใๅ
จใฆใ็ใชใ `true` ใ่ฟใใใใใงใชใใชใ `false` ใ่ฟใใ
ใพใใใฌใทใผใใ็ฉบใฎใใใทใฅใฎๅ ดๅใๅผๆฐใ็ฉบใฎใใใทใฅใชใ `true` ใ่ฟใใใใใงใชใใชใ `false` ใ่ฟใใ
```ruby
user = { id: 1, name: "homu", age: 14 }
# name ่ฆ็ด ใ data ใซใใใฎใง true
p ({ name: "homu" } === user)
# => true
# ่คๆฐใฎ่ฆ็ด ใใใฃใฆใ OK
p ({ id: 1, name: "homu", age: 14 } === user)
# => true
# name ่ฆ็ด ใ user ใซใใใใๅคใ้ใใฎใง false
p ({ name: "name" } === user)
# => false
# ใญใผใฎ่ฆ็ด ใๅผๆฐใซใชใใฎใง false
p ({ number: 42 } === user)
# => false
# 1ใคใงใใญใผใฎ่ฆ็ด ใใชใๅ ดๅใ false
p ({ id: 1, name: "homu", number: 42 } === user)
# => false
# ใฌใทใผใใ็ฉบใฎใใใทใฅใชใ false
p ({} == user)
# => false
# ็ฉบใฎใใใทใฅๅๅฃซใชใ true
p ({} == {})
# => true
# ๅผๆฐใใใใทใฅไปฅๅคใชใ false
p ({ id: 42 } == 42)
# => false
# #=== ใงๆฏ่ผใใฆใใใฎใงใใใใใใจใใงใใ
p ({ name: /^h/ } === user)
# => true
p ({ age: (1..20) } === user)
# => true
p ({ age: Integer } === user)
# => true
```
## ใฆใผในใฑใผใน
### ใใชใใผใทใงใณ
case-when ใงใฏ `===` ใไฝฟ็จใใฆๅคใๆฏ่ผใใฆใใใฎใงใ`Hash#===` ใๅฉ็จใใใใจใงๆฌกใฎใใใซๆกไปถๅๅฒใ่กใใใจใๅบๆฅใใ
```ruby
def validation user
case user
# name ใซๅฏพใใใใชใใผใทใงใณ
when { name: /^[a-z]/ }
raise "ๅๅใฎๅ
้ ญใๅฐๆๅญใฎๅ ดๅใฏ็ป้ฒใงใใพใใ"
# age ใซๅฏพใใใใชใใผใทใงใณ
when { age: (0..20) }
raise "0ใ20ๆญณใฏ็ป้ฒใงใใพใใ"
# ๅ่ฆ็ด ใไปปๆใฎใฏใฉในใฎใคใณในใฟใณในใใฉใใใฎใใชใใผใทใงใณ
when { id: Integer, name: String, age: Integer }
true
else
false
end
end
# ๆกไปถใๆบใใใฆใใใฎใง OK
mami = { id: 1, name: "Mami", age: 21 }
validation mami
# => true
# name ใๅฐๆๅญใใๅงใพใฃใฆใใใฎใง NG
mado = { id: 2, name: "mado", age: 13 }
validation mado
# => ๅๅใฎๅ
้ ญใๅฐๆๅญใฎๅ ดๅใฏ็ป้ฒใงใใพใใ (RuntimeError)
# age ใ 0ใ20ๆญณไปฅๅ
ใชใฎใง NG
homu = { id: 3, name: "Homu", age: 14 }
validation homu
# => 0ใ20ๆญณใฏ็ป้ฒใงใใพใใ (RuntimeError)
```
### `Enumerable#grep`
`Enumerable#grep` ใฏๅ
้จใง `===` ใไฝฟ็จใใๆฏ่ผใ่กใฃใฆใใใฎใงใๆฌกใฎใใใซไปปๆใฎ Hash ใฎใญใผใฎ่ฆ็ด ใซๅฏพใใฆๆค็ดขใ่กใใใจใๅบๆฅใใ
```ruby
data = [
{ id: 1, name: "Homu", age: 13 },
{ id: 2, name: "mami", age: 14 },
{ id: 3, name: "Mado", age: 21 },
{ id: 4, name: "saya", age: 14 },
]
# ็นๅฎใฎ่ฆ็ด ใๅซใพใใฆใใ Hash ใฎใฟใ็ตใ่พผใ
p data.grep(name: /m/)
# => [{:id=>1, :name=>"Homu", :age=>13}, {:id=>2, :name=>"mami", :age=>14}]
p data.grep(age: (1..20))
# => [{:id=>1, :name=>"Homu", :age=>13}, {:id=>2, :name=>"mami", :age=>14}, {:id=>4, :name=>"saya", :age=>14}]
```
## ่ฃ่ถณ1๏ผ `==` ใงใฏใชใใฆ `===` ใงๆฏ่ผใใ็็ฑ
* `===` ใไฝฟ็จใใใใจใงใใ็ดฐใใใปๆฝ่ฑก็ใชๆกไปถใๆๅฎใใใใจใๅบๆฅใ
* `Class` ใ `Regexp`ใ`Proc` ใชใฉใงๆฏ่ผใใใใจใๅบๆฅใ
* ๅ
้จใง `===` ใไฝฟ็จใใฆใใๅ ดๅใ `==` ใงๆฏ่ผใใใๅ ดๅใฏ `obj.method(:==)` ใๆธกใใฐๅฎ็พๅบๆฅใใใใใฎ้ใฏๅบๆฅใชใ
* ๅ
้จใง `==` ใไฝฟ็จใใฆใใๅ ดๅใ `===` ใงๆฏ่ผใใใใใฆใๅบๆฅใชใ
## ่ฃ่ถณ2๏ผ ็ฉบใฎใใใทใฅใฎๆฏ่ผใซ้ขใใฆ
* `Object#===` ใฎๅ ดๅใ ใจ `{} === 42` ใไพๅคใงใฏใชใใฆ `false` ใ่ฟใใฆใใใฎใงใ`Hash#===` ใ `false` ใ่ฟใใใใซใใ
* `{} === {}` ใ `true` ใ่ฟใใฎใๅๆงใฎ็็ฑใซใชใใพใ
* ใใใซใใไปฅไธใฎใใใชๆขๅญใฎใณใผใใไบๆๆงใๅฃใใใจใชใๅไฝใใใใจๆใใพใ
```ruby
def check n
case n
when {}
"Empty Hash"
when []
"Empty Array"
when 0
"Zero"
else
"Not empty"
end
end
p check({}) # => "Empty Hash"
p check([]) # => "Empty Array"
p check(0) # => "Zero"
p check({ name: "mado" }) # => "Not empty"
```
ไปฅไธใ`Hash#===` ใซ้ขใใๆๆกใซใชใใพใใ
ๆๅใซ้ขใใฆ็ๅ็นใๆ่ฆใชใฉใใใใพใใใใณใกใณใ้ ใใใจๅฉใใใพใใ
---Files--------------------------------
hash_eqq.patch (3.54 KB)
--
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>