hanami / utils

Ruby core extentions and class utilities for Hanami

Home Page:http://hanamirb.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Remove `Utils::Duplicable`

jodosha opened this issue · comments

  • Replace the occurrences of Utils::Duplicable with Object#dup
  • Remove Utils::Duplicable

Use the unstable branch for this enhancement.


This change should happen after we bumped minimum version of Ruby to 2.4.


Please note, we cannot deprecate Utils::Duplicable in v1.3.0 because we will still support Ruby 2.3 for that version. Ruby 2.3 doesn't have a consistent behavior for Object#dup. So if we deprecate, we'll generate tons of annoying warnings that can't be fixed by our users.

commented

i would like to take this on but was initially looking and can't seem to find which file or code this occurs in?

@pawan92 Thanks for the help! @jodosha meant Hanami::Utils::Duplicable, instead of Hanami::Utils::Duplicate.

Just fixed the original post and title :)

commented

got it! just to clarify you say remove utils::duplicable and also replace it..? do you want that to be removed and replaced with Object#dup

Remove the file and replace the instances where it’s used with Object#dup. Does that answer your question? Make sure to do it on the unstable branch :)

commented

I think so. let me try it out! :)

@pawan92 thanks for giving it a try.


Please note that this will be possible only when the unstable branch will be ported to MRI 2.4+ and JRuby 9.2.0.0+. Because these versions of Ruby make Object#dup consistent across all the core primitives.

For instance on MRI 2.3 1.dup raises an exception, whereas on 2.4+ it works just fine.


To recap, we should merge this first: #269 in unstable, and then you'll be able to successfully remove Utils::Duplicable.

Hi! I've tried to make a PR for this issue, but without Utils::Duplicable we still cannot make dup for Complex and Rational

@morron Which version of Ruby?

irb(main):001:0> require "complex"
=> false
irb(main):002:0> Complex(1).dup
=> (1+0i)
irb(main):003:0> Rational(1).dup
=> (1/1)
irb(main):004:0> RUBY_VERSION
=> "2.5.1"

@jodosha
on 2.4

pry(main)> Complex(1).dup
TypeError: can't copy Complex
from (pry):2:in `initialize_copy'
pry(main)> RUBY_VERSION
=> "2.4.2"

🤦‍♂️ Alright, thanks for spotting this important bit! We'll discuss if to bump directly to 2.5 for Hanami 2.0.

Closed by #322