When using Ruby 3.2, an error occurs.
Closed this issue · 2 comments
ashimomura commented
I have issues
When using Ruby 3.2, an error occurs.
$ irb
irb(main):001:0> require 'type_struct'
/Users/ashimomura/type_struct/lib/type_struct/union.rb:34:in `include': Refinement#include has been removed (TypeError)
include Unionable
^^^^^^^^^
from /Users/ashimomura/type_struct/lib/type_struct/union.rb:34:in `block in <module:Ext>'
from /Users/ashimomura/type_struct/lib/type_struct/union.rb:33:in `refine'
from /Users/ashimomura/type_struct/lib/type_struct/union.rb:33:in `<module:Ext>'
from /Users/ashimomura/type_struct/lib/type_struct/union.rb:32:in `<class:Union>'
from /Users/ashimomura/type_struct/lib/type_struct/union.rb:8:in `<class:TypeStruct>'
from /Users/ashimomura/type_struct/lib/type_struct/union.rb:1:in `<top (required)>'
from /Users/ashimomura/type_struct/lib/type_struct.rb:4:in `require'
from /Users/ashimomura/type_struct/lib/type_struct.rb:4:in `<class:TypeStruct>'
from /Users/ashimomura/type_struct/lib/type_struct.rb:3:in `<top (required)>'
from (irb):2:in `require'
from (irb):2:in `<main>'
from /Users/ashimomura/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/irb-1.6.2/exe/irb:11:in `<top (required)>'
from /Users/ashimomura/.rbenv/versions/3.2.2/bin/irb:25:in `load'
from /Users/ashimomura/.rbenv/versions/3.2.2/bin/irb:25:in `<main>'
It's likely that starting from Ruby 3.2, you can no longer use include
within refine
, so in Ruby 3.2, it seems necessary to use import_methods
as an alternative.
https://docs.ruby-lang.org/en/3.1/NEWS_md.html
New class which represents a module created by Module#refine. include and prepend are deprecated, and import_methods is added instead.
Environment details
- Ruby: 3.2.2
- type_struct: 0.8.0
ksss commented
@ashimomura
Thank you for using type_sturct ❤️
I released v1.0.0.
Please check it out!
ashimomura commented
I have confirmed that it works with Ruby 3.2.
$ gem update type_struct
Updating installed gems
Updating type_struct
Fetching type_struct-1.0.0.gem
Successfully installed type_struct-1.0.0
Parsing documentation for type_struct-1.0.0
Installing ri documentation for type_struct-1.0.0
Done installing documentation for type_struct after 0 seconds
Parsing documentation for type_struct-1.0.0
Done installing documentation for type_struct after 0 seconds
Gems updated: type_struct0
$ ruby --version
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [arm64-darwin23]
$ irb
irb(main):001:0> require 'type_struct'
=> true
irb(main):002:0> using TypeStruct::Union::Ext
=> main
irb(main):003:1> Foo = TypeStruct.new(bar: TrueClass | FalseClass)
=> Foo
irb(main):006:0> Foo.from_hash(bar: true).bar
=> true
@ksss Many thanks!