method
to_s
v1_9_1_378 -
Show latest stable
- Class:
IPAddr
to_s()public
Returns a string containing the IP address representation.
# File lib/ipaddr.rb, line 194
def to_s
str = to_string
return str if ipv4?
str.gsub!(/\b0{1,3}([\da-f]+)\b/, '\1')
loop do
break if str.sub!(/\A0:0:0:0:0:0:0:0\Z/, '::')
break if str.sub!(/\b0:0:0:0:0:0:0\b/, ':')
break if str.sub!(/\b0:0:0:0:0:0\b/, ':')
break if str.sub!(/\b0:0:0:0:0\b/, ':')
break if str.sub!(/\b0:0:0:0\b/, ':')
break if str.sub!(/\b0:0:0\b/, ':')
break if str.sub!(/\b0:0\b/, ':')
break
end
str.sub!(/:{3,}/, '::')
if /\A::(ffff:)?([\da-f]{1,4}):([\da-f]{1,4})\Z/ =~ str
str = sprintf('::%s%d.%d.%d.%d', $1, $2.hex / 256, $2.hex % 256, $3.hex / 256, $3.hex % 256)
end
str
end Related methods
- Instance methods
- &
- <<
- <=>
- ==
- ===
- >>
- hton
- include?
- inspect
- ip6_arpa
- ip6_int
- ipv4?
- ipv4_compat
- ipv4_compat?
- ipv4_mapped
- ipv4_mapped?
- ipv6?
- mask
- native
- reverse
- succ
- to_i
- to_range
- to_s
- to_string
- |
- ~
- Class methods
- new
- new_ntoh
- ntop
- Protected methods
-
mask! -
set - Private methods
-
_reverse -
_to_string -
addr_mask -
coerce_other -
in6_addr -
in_addr