With bundler, an OpenStruct can't have a field called 'gem' (and it's really hard to troubleshoot -- redefine_method)
まだ誰も着手していません。
評価
調査の方向性
ruby と bundle exec で OpenStruct.new(gem: 'foobar').gem を実行して失敗を再現し、その後、316 行目付近の Bundler の lib/bundler/rubygems_integration.rb を調べます。この挙動が OpenStruct と Bundler のどちらに属するのかを判断し、選択した修正によって属性が使用可能になり、不可解なエラーが回避されることを示すテストを追加します。
索引モデルが issue の本文から書いたものです。
説明
After many hours of head-scratching, I can offer this bug report:
OpenStruct.new(gem: 'foobar').gem
The above code works in "bare" ruby, but not with bundler.
Steps to reproduce:
$ mkdir ostruct-bug
$ cd ostruct-bug
$ echo "source 'https://rubygems.org'" > Gemfile
$ bundle install
The Gemfile specifies no dependencies
Resolving dependencies...
Bundle complete! 0 Gemfile dependencies, 1 gem now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
$ ruby -v
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20]
$ bundle -v
Bundler version 2.1.4
$ ruby -e "require 'ostruct' ; puts OpenStruct.new(gem: 'foobar').gem"
foobar
$ bundle exec ruby -e "require 'ostruct' ; puts OpenStruct.new(gem: 'foobar').gem"
Traceback (most recent call last):
1: from -e:1:in `<main>'
/Users/ikatz/.rbenv/versions/2.7.2/lib/ruby/2.7.0/bundler/rubygems_integration.rb:316:in `block (2 levels) in replace_gem': wrong number of arguments (given 0, expected 1+) (ArgumentError)
$ bundle exec ruby -e "require 'ostruct' ; puts OpenStruct.new(germ: 'foobar').germ"
foobar
Whether or not this is a problem with bundler (vs ostruct), the error is very unhelpful -- gem seems to all appearances like a perfectly valid attribute name and jumping into bundler source is generally not my first thought when debugging my own project.
The relevant bundler code is here:
https://github.com/rubygems/bundler/blob/master/lib/bundler/rubygems_integration.rb#L316
It would seem that the correct behavior in ostruct would be to check whether a method name is available (possibly with self.respond_to?(new_attribute_name) at the time the attribute is being defined , so that it can produce a warning or exception immediately instead of cryptic behavior when the attribute is later accessed.
- 主要言語
- Ruby
- スター
- 175
- フォーク
- 35
- 平均マージ
- 16時間 14分
- マージ済み PR(30日)
- 1
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby/ostruct のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
TheOdinProject/curriculum#31417 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
glossarist/glossarist-ruby#238 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
palladius/rails8-app-on-gcp#145 ·