different behavior of stdlib ostruct vs. ostruct-gem
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
Research direction
Start in lib/ostruct.rb at the []= call reported at line 304, and reproduce the Ruby 3.0 behavior with ostruct 0.5.0 using the examples in the issue. Compare repeated assignments and dup with stdlib OpenStruct; done means updated assignments retain the expected symbol key and dup no longer raises the shown NoMethodError.
Written by the indexing model from the issue text.
Description
I am on Ruby 3.0
With stdlib ostruct I get:
irb(main):002:0> x = OpenStruct.new
=> #<OpenStruct>
irb(main):002:0> x.varname1 = 'varval 1'
=> "varval 1"
irb(main):003:0> x.to_h
=> {:varname1=>"varval 1"}
irb(main):004:0> x.varname1 = 'varval 2'
=> "varval 2"
irb(main):005:0> x.to_h
=> {:varname1=>"varval 2"}
irb(main):006:0> x.varname2 = 'varval 3'
=> "varval 3"
irb(main):007:0> x.to_h
=> {:varname1=>"varval 2", :varname2=>"varval 3"}
irb(main):008:0> x.varname2 = 'varval 4'
=> "varval 4"
irb(main):009:0> x.to_h
=> {:varname1=>"varval 2", :varname2=>"varval 4"}
Starting with version 0.5.0 of the ostruct-gem: I get:
irb(main):001:0> x = OpenStruct.new
=> #<OpenStruct>
irb(main):002:0> x.varname1 = 'varval 1'
=> "varval 1"
irb(main):003:0> x.to_h
=> {:varname1=>"varval 1"}
irb(main):004:0> x.varname1 = 'varval 2'
=> "varval 2"
irb(main):005:0> x.to_h
=> {:varname1=>"varval 1", false=>"varval 2"}
irb(main):006:0> x.varname2 = 'varval 3'
=> "varval 3"
irb(main):007:0> x.to_h
=> {:varname1=>"varval 1", false=>"varval 2", :varname2=>"varval 3"}
irb(main):008:0> x.varname2 = 'varval 4'
=> "varval 4"
irb(main):009:0> x.to_h
=> {:varname1=>"varval 1", false=>"varval 4", :varname2=>"varval 3"}
one of many side effects is:
irb(main):009:0> y = x.dup
/var/lib/gems/3.0.0/gems/ostruct-0.5.0/lib/ostruct.rb:304:in `[]=': undefined method `to_sym' for false:FalseClass (NoMethodError)
Did you mean? to_s
- Dominant language
- Ruby
- Stars
- 175
- Forks
- 35
- Avg merge
- 16h 14m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ruby/ostruct
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
user-reported
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kong/developer.konghq.com#7316 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TheOdinProject/curriculum#31408 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
notch8/utk_knapsack#148 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Homebrew/homebrew-cask#288729 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100