From a44e5018eb6d19ae4955ce2ec0b0f45f46fb7dc3 Mon Sep 17 00:00:00 2001
From: Mike Mackintosh <m@zyp.io>
Date: Mon, 26 Jan 2015 16:27:05 -0500
Subject: [PATCH] added ipv4 to_h method

---
 lib/ipaddress/ipv4.rb | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb
index 716d4d9..0cb30ab 100644
--- a/lib/ipaddress/ipv4.rb
+++ b/lib/ipaddress/ipv4.rb
@@ -230,6 +230,22 @@ module IPAddress;
     alias_method :to_i, :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
     # in a network byte order format.
-- 
GitLab