Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when trying to set prefix using other ip instance #142

Open
gucki opened this issue Sep 1, 2023 · 0 comments
Open

Exception when trying to set prefix using other ip instance #142

gucki opened this issue Sep 1, 2023 · 0 comments

Comments

@gucki
Copy link

gucki commented Sep 1, 2023

I guess this should work:

  irb(main):002:0> IPAddress.parse("1.2.3.4/32").tap{ |ip| ip.prefix = Settings.ipv4.address.prefix }
  /usr/local/bundle/bundler/gems/ipaddress-fb310dff8889/lib/ipaddress/prefix.rb:96:in `initialize': Prefix must be in range 0..32, got: 24 (ArgumentError)

        raise ArgumentError, "Prefix must be in range 0..32, got: #{num}"
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

An easy workaround is to use to_i on the prefix:

irb(main):007:0> IPAddress.parse("1.2.3.4/32").tap{ |ip| ip.prefix = Settings.ipv4.address.prefix.to_i }
=> #<IPAddress::IPv4:0x00007fb6e9bc0870 @address="1.2.3.4", @allocator=0, @octets=[1, 2, 3, 4], @prefix=24, @u32=16909060>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant