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 1763
1763:     def self.create(arg)
1764:       case arg
1765:       when IPv4
1766:         return arg
1767:       when Regex
1768:         if (0..255) === (a = $1.to_i) &&
1769:            (0..255) === (b = $2.to_i) &&
1770:            (0..255) === (c = $3.to_i) &&
1771:            (0..255) === (d = $4.to_i)
1772:           return self.new([a, b, c, d].pack("CCCC"))
1773:         else
1774:           raise ArgumentError.new("IPv4 address with invalid value: " + arg)
1775:         end
1776:       else
1777:         raise ArgumentError.new("cannot interpret as IPv4 address: #{arg.inspect}")
1778:       end
1779:     end

[Source]

      # File lib/resolv.rb, line 1781
1781:     def initialize(address)
1782:       unless address.kind_of?(String) && address.length == 4
1783:         raise ArgumentError.new('IPv4 address must be 4 bytes')
1784:       end
1785:       @address = address
1786:     end

Public Instance methods

[Source]

      # File lib/resolv.rb, line 1802
1802:     def ==(other)
1803:       return @address == other.address
1804:     end

[Source]

      # File lib/resolv.rb, line 1806
1806:     def eql?(other)
1807:       return self == other
1808:     end

[Source]

      # File lib/resolv.rb, line 1810
1810:     def hash
1811:       return @address.hash
1812:     end

[Source]

      # File lib/resolv.rb, line 1793
1793:     def inspect
1794:       return "#<#{self.class} #{self.to_s}>"
1795:     end

[Source]

      # File lib/resolv.rb, line 1797
1797:     def to_name
1798:       return DNS::Name.create(
1799:         '%d.%d.%d.%d.in-addr.arpa.' % @address.unpack('CCCC').reverse)
1800:     end

[Source]

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

[Validate]