You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
With bundler, an OpenStruct can't have a field called 'gem' (and it's really hard to troubleshoot -- redefine_method) #27
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 installThe Gemfile specifies no dependenciesResolving dependencies...Bundle complete! 0 Gemfile dependencies, 1 gem now installed.Use `bundle info [gemname]` to see where a bundled gem is installed.
$ ruby -vruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin20]
$ bundle -vBundler 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.
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.
Activity
olleolleolle commentedon May 27, 2021
👋 @deivid-rodriguez Hope this report finds you well!