Skip to content
Snippets Groups Projects
Commit a44e5018 authored by Mike Mackintosh's avatar Mike Mackintosh
Browse files

added ipv4 to_h method

parent ce5b5247
No related branches found
No related tags found
No related merge requests found
...@@ -230,6 +230,22 @@ module IPAddress; ...@@ -230,6 +230,22 @@ module IPAddress;
alias_method :to_i, :u32 alias_method :to_i, :u32
alias_method :to_u32, :u32 alias_method :to_u32, :u32
#
# Returns the address portion in
# hex
#
# ip = IPAddress("10.0.0.0")
#
# ip.to_h
# #=> 0a000000
#
def hex
hex = @octets.map{|o| o.to_s(16).rjust(2, '0') }.join()
"#{hex}"
end
alias_method :to_h, :hex
alias_method :to_hex, :hex
# #
# Returns the address portion of an IPv4 object # Returns the address portion of an IPv4 object
# in a network byte order format. # in a network byte order format.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment