Class Resolv::IPv4
In: lib/resolv.rb
Parent: Object

Methods

==   create   eql?   hash   inspect   new   to_name   to_s  

Constants

Regex = /\A(\d+)\.(\d+)\.(\d+)\.(\d+)\z/

Attributes

address  [R] 

Public Class methods

[Source]

      # File lib/resolv.rb, line 1717
1717:     def self.create(arg)
1718:       case arg
1719:       when IPv4
1720:         return arg
1721:       when Regex
1722:         if (0..255) === (a = $1.to_i) &&
1723:            (0..255) === (b = $2.to_i) &&
1724:            (0..255) === (c = $3.to_i) &&
1725:            (0..255) === (d = $4.to_i)
1726:           return self.new([a, b, c, d].pack("CCCC"))
1727:         else
1728:           raise ArgumentError.new("IPv4 address with invalid value: " + arg)
1729:         end
1730:       else
1731:         raise ArgumentError.new("cannot interpret as IPv4 address: #{arg.inspect}")
1732:       end
1733:     end

[Source]

      # File lib/resolv.rb, line 1735
1735:     def initialize(address)
1736:       unless address.kind_of?(String) && address.length == 4
1737:         raise ArgumentError.new('IPv4 address must be 4 bytes')
1738:       end
1739:       @address = address
1740:     end

Public Instance methods

[Source]

      # File lib/resolv.rb, line 1756
1756:     def ==(other)
1757:       return @address == other.address
1758:     end

[Source]

      # File lib/resolv.rb, line 1760
1760:     def eql?(other)
1761:       return self == other
1762:     end

[Source]

      # File lib/resolv.rb, line 1764
1764:     def hash
1765:       return @address.hash
1766:     end

[Source]

      # File lib/resolv.rb, line 1747
1747:     def inspect
1748:       return "#<#{self.class} #{self.to_s}>"
1749:     end

[Source]

      # File lib/resolv.rb, line 1751
1751:     def to_name
1752:       return DNS::Name.create(
1753:         '%d.%d.%d.%d.in-addr.arpa.' % @address.unpack('CCCC').reverse)
1754:     end

[Source]

      # File lib/resolv.rb, line 1743
1743:     def to_s
1744:       return sprintf("%d.%d.%d.%d", *@address.unpack("CCCC"))
1745:     end

[Validate]