Guest User

Untitled

a guest
Feb 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. class Integer
  2. def to_ip_ary
  3. [self].pack("N").unpack("C*")
  4. end
  5. def to_ip
  6. to_ip_ary.join(".")
  7. end
  8. end
  9.  
  10. class Array
  11. def to_ip_num
  12. #(0..3).inject(0){|acc,i| acc + (self[i] << (24 - (8 * i)))}
  13. self.pack("C*").unpack("N")[0]
  14. end
  15. end
  16.  
  17. class String
  18. def to_ip_num
  19. self.split(".").map!{|v| v.to_i}.to_ip_num
  20. end
  21. end
Add Comment
Please, Sign In to add comment