[#112457] [Ruby master Feature#19443] Cache `Process.pid` — "byroot (Jean Boussier) via ruby-core" <ruby-core@...>
Issue #19443 has been reported by byroot (Jean Boussier).
16 messages
2023/02/16
[#112584] [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system — "normalperson (Eric Wong) via ruby-core" <ruby-core@...>
Issue #19465 has been reported by normalperson (Eric Wong).
9 messages
2023/02/25
[#112595] [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system
— "nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@...>
2023/02/25
SXNzdWUgIzE5NDY1IGhhcyBiZWVuIHVwZGF0ZWQgYnkgbm9idSAoTm9idXlvc2hpIE5ha2FkYSku
[#112613] Re: [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system
— Eric Wong via ruby-core <ruby-core@...>
2023/02/26
"nobu (Nobuyoshi Nakada) via ruby-core" <ruby-core@ml.ruby-lang.org> wrote:
[#112615] Re: [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system
— SHIBATA Hiroshi via ruby-core <ruby-core@...>
2023/02/27
MzUxMzZlMWU5YzIzMmFkN2EwMzQwN2I5OTJiMmU4NmI2ZGY0M2Y2MyBpcyBicm9rZW4gd2l0aCBg
[#112626] Re: [Ruby master Feature#19465] [PATCH] reuse open(2) from rb_file_load_ok on POSIX-like system
— Eric Wong via ruby-core <ruby-core@...>
2023/02/28
```
[ruby-core:112342] [Ruby master Feature#15374] Proposal: Enable refinements to `#method_missing`
From:
"shreeve (Steve Shreeve) via ruby-core" <ruby-core@...>
Date:
2023-02-10 19:41:02 UTC
List:
ruby-core #112342
Issue #15374 has been updated by shreeve (Steve Shreeve).
> I don't see any real-world usage of allowing #method_missing refinable. Maybe it can be used only for tricks and obfusticated code.
We use this heavily and it would be great if `method_missing` could be refinable.
Here's an example:
```ruby
class Hash
alias_method :default_lookup, :[]
def [](key, miss=nil)
key?(key) and return default_lookup(key) || miss
ary = key.to_s.split(/(?:[.\/\[]|\][.\/]?)/)
val = ary.inject(self) do |obj, sub|
if obj == self then default_lookup(sub.to_sym)
elsif obj == nil then break
elsif sub =~ /\A-?\d*\z/ then obj[sub.to_i]
else obj[sub.to_sym]
end
end or miss
end
def method_missing(name, *args)
name =~ /=$/ ? send(:[]=, $`.to_sym, *args) : send(:[], name, *args)
end
end
book = {
name: "Ruby Object Model",
url: [
"https://google.com",
"https://pepsi.com",
"https://byu.edu",
],
team: {
boss: {
name: "Mark",
age: 23,
},
janitor: {
name: "Bob",
age: 56,
kids: %w[ Billy Sue Tim Nebo Dash ],
},
},
}
p book.name # => "Ruby Object Model"
p book.color # => nil
p book.color("red") # => "red"
p book.url[2] # => "https://byu.edu"
p book["team/janitor/age"] # => 56
p book["team.janitor.age"] # => 56
p book["team/janitor/song", "None"] # => "None"
p book["team/janitor/kids[3]"] # => "Nebo"
```
This approach has been *extremely* helpful and useful, but I can't get it to work with refinements and I always feel a little dirty with bastardizing the core `Hash` class.
Can this code be made to work with refinements? This is a real world case, where we rely on this heavily for an api in production for several years. Refinement support would be great!
----------------------------------------
Feature #15374: Proposal: Enable refinements to `#method_missing`
https://bugs.ruby-lang.org/issues/15374#change-101786
* Author: osyo (manga osyo)
* Status: Rejected
* Priority: Normal
----------------------------------------
Proposal enable refinements to `#method_missing`.
It can be used in the following cases.
```ruby
# Access key value with method
using Module.new {
refine Hash do
# name is Symbol or String
def method_missing(name)
self[name.to_sym] || self[name.to_s]
end
end
}
hash = { name: "homu", "age" => 14 }
pp hash.name
# => "homu"
pp hash.age
# => "age"
```
`method_missing` is hard hacking.
I would like to use Refinements with `method_missing`.
pull request: https://github.com/ruby/ruby/pull/2036
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/