Module: BetterIpaddr::ClassMethods

Includes:
Constants
Included in:
IPAddr
Defined in:
lib/better_ipaddr/methods.rb

Constant Summary

Constants included from Constants

BetterIpaddr::Constants::FAMILY_TO_BIT_LENGTH, BetterIpaddr::Constants::NETMASK_TO_PREFIX_LENGTH, BetterIpaddr::Constants::PREFIX_LENGTH_TO_NETMASK, BetterIpaddr::Constants::SYMBOL_TO_FAMILY

Instance Method Summary collapse

Instance Method Details

#[](address, family) ⇒ IPAddr #[](address, family) ⇒ IPAddr #[](address) ⇒ IPAddr

Overloads:

  • #[](address, family) ⇒ IPAddr

    Wrapper for IPAddr.new that accepts a symbolic family name and returns a specialized IPAddr subclass.

    Parameters:

    • address (Integer)

      the integer representation of the address

    • family (Symbol)

      a symbol named for the address’s address family, one of :ipv4, :ipv6, or :mac.

    Returns:

  • #[](address, family) ⇒ IPAddr

    Wrapper for IPAddr.new that accepts a symbolic family name and returns a specialized IPAddr subclass.

    Parameters:

    • address (Integer)

      the integer representation of the address

    • family (Integer)

      the magic number representing the address’s address family.

    Returns:

  • #[](address) ⇒ IPAddr

    Wrapper for IPAddr.new that accepts the string representation of an address returns a specialized IPAddr subclass.

    Parameters:

    • address (String)

      the string representation of the address

    Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/better_ipaddr/methods.rb', line 30

def [](address, family = nil)
  instance = case family
             when Symbol
               self[address, SYMBOL_TO_FAMILY.fetch(family)]
             when IPAddr
               address
             when nil
               new(address)
             else
               new(address, family)
             end
  IPAddr::Base.specialize(instance)
end