Created
February 9, 2018 10:07
-
-
Save td512/0f6ff0e52c24e357daa0734dc4b764f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The IP. In this example we'll get it from the environment | |
ip = ARGV[0] | |
# First, let's split the IP into octets and map them to integers | |
ip = ip.split(".").map(&:to_i) | |
# Now that's done, let's loop through each octet | |
ip.each do |octet| | |
# Check if the length of the integer is still more than 1 AND the first character in the octet is 0 | |
while octet.digits.count > 1 && octet[0] == '0' do | |
# Strip the 0 out | |
octet[0] == '' | |
end | |
end | |
# Last couple of things. First reassemble the array of octets into the IP again | |
ip = ip.join(".") | |
# Finally, let's output said IP | |
puts ip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment