Skip to content

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

@gucki

Description

@gucki

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>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions