[#92891] Question: ruby 2.7.0-preview1 also upgrades bundler to 2.1.0.pre.1? — Al Snow <jasnow@...>
Tried the new 2.7.0-preview1 upgrade to Ruby and see that bundler is also upgraded (to 2.1.0.pre.1).
5 messages
2019/05/30
[#92892] Re: Question: ruby 2.7.0-preview1 also upgrades bundler to 2.1.0.pre.1?
— SHIBATA Hiroshi <hsbt@...>
2019/05/30
Bundler 2.1.0.pree.1 is the expected version.
[ruby-core:92513] [Ruby trunk Feature#15815] Add option to raise NoMethodError for OpenStruct
From:
mtsmfm@...
Date:
2019-05-01 13:52:21 UTC
List:
ruby-core #92513
Issue #15815 has been reported by mtsmfm (Fumiaki Matsushima).
----------------------------------------
Feature #15815: Add option to raise NoMethodError for OpenStruct
https://bugs.ruby-lang.org/issues/15815
* Author: mtsmfm (Fumiaki Matsushima)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
GitHub PR: https://github.com/ruby/ruby/pull/2164
Currently, `OpenStruct#method_missing` returns `nil` even if the key isn't registered.
```ruby
require 'ostruct'
os = OpenStruct.new({a: 1})
os.a #=> 1
os.b #=> nil
```
I'd like to add `exception` option to raise `NoMethodError` in such case.
```ruby
require 'ostruct'
os = OpenStruct.new({a: 1}, exception: true)
os.a #=> 1
os.b #=> NoMethodError
```
## Use case
I sometimes use OpenStruct as a JSON API response wrapper.
It's useful to use method call instead of key access (`obj[:key]`) because we can use `Symbol#to_proc` if it's a method (for example `users.map(&:id)`)
But I want to prevent typo for a key name. Currently `users.map(&:idd)` just returns `[nil,...]`
Even if we have this `exception` option, we can't enable this option for JSON parser easily though:
```ruby
JSON.parse(response, object_class: Class.new(OpenStruct) { def initialize(hash); super(hash, exception: true); end })
```
What do you think?
----
I've searched with "openstruct nomethoderror" on bugs.ruby-lang.org though, please let me know if it's duplicated.
https://bugs.ruby-lang.org/search?utf8=%E2%9C%93&scope=&q=nomethoderror+openstruct
--
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>