Class: Gem::Resolv::IPv4
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rubygems/vendor/resolv/lib/resolv.rb |
Overview
A DNS
IPv4
address.
Constant Summary
-
Regex =
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 2905/\A(#{Regex256})\.(#{Regex256})\.(#{Regex256})\.(#{Regex256})\z/
-
Regex256 =
Regular expression
IPv4
addresses must match./0 |1(?:[0-9][0-9]?)? |2(?:[0-4][0-9]?|5[0-5]?|[6-9])? |[3-9][0-9]?/x
Class Method Summary
- .create(arg)
- .new(address) ⇒ IPv4 constructor Internal use only
Instance Attribute Summary
-
#address
readonly
The raw
IPv4
address as a String.
Instance Method Summary
-
#to_name
Turns this
IPv4
address into aDNS::Name
. - #==(other) Internal use only
- #eql?(other) ⇒ Boolean Internal use only
- #hash Internal use only
- #inspect Internal use only
- #to_s Internal use only
Constructor Details
.new(address) ⇒ IPv4
This method is for internal use only.
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 2925
def initialize(address) # :nodoc: unless address.kind_of?(String) raise ArgumentError, 'IPv4 address must be a string' end unless address.length == 4 raise ArgumentError, "IPv4 address expects 4 bytes but #{address.length} bytes" end @address = address end
Class Method Details
.create(arg)
[ GitHub ]# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 2907
def self.create(arg) case arg when IPv4 return arg when Regex if (0..255) === (a = $1.to_i) && (0..255) === (b = $2.to_i) && (0..255) === (c = $3.to_i) && (0..255) === (d = $4.to_i) return self.new([a, b, c, d].pack("CCCC")) else raise ArgumentError.new("IPv4 address with invalid value: " + arg) end else raise ArgumentError.new("cannot interpret as IPv4 address: #{arg.inspect}") end end
Instance Attribute Details
#address (readonly)
The raw IPv4
address as a String.
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 2941
attr_reader :address
Instance Method Details
#==(other)
This method is for internal use only.
[ GitHub ]
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 2959
def ==(other) # :nodoc: return @address == other.address end
#eql?(other) ⇒ Boolean
This method is for internal use only.
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 2963
def eql?(other) # :nodoc: return self == other end
#hash
This method is for internal use only.
[ GitHub ]
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 2967
def hash # :nodoc: return @address.hash end
#inspect
This method is for internal use only.
[ GitHub ]
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 2947
def inspect # :nodoc: return "#<#{self.class} #{self}>" end
#to_name
Turns this IPv4
address into a DNS::Name
.
#to_s
This method is for internal use only.
[ GitHub ]
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 2943
def to_s # :nodoc: return sprintf("%d.%d.%d.%d", *@address.unpack("CCCC")) end