Skip to content

Instantly share code, notes, and snippets.

@alexdantas
Created April 4, 2014 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexdantas/9982166 to your computer and use it in GitHub Desktop.
Save alexdantas/9982166 to your computer and use it in GitHub Desktop.
Shows all valid hosts on a Windows machine
# This is where it all starts and ends
begin
# It saves all the lines of the file inside
# the 'contents' variable.
# Note that we use '/' as the path separator
# (and not '\')
contents = File.read("C:/Windows/system32/drivers/etc/hosts")
# We're going through each line of 'contents',
# assigning one at a time to the 'line' variable.
contents.each_line do |line|
# For each 'line', we'll show it if it's
# not a comment.
puts line if not line.match(/^\s*#/)
# 'puts' shows stuff on the screen.
# 'match' compares the string to a Regular Expression.
#
# Idk if you know what those are, but think of
# them as indicators of what should be on a string.
#
# That '/^\s*#/' is trying to see if the string 'line'
# * Begins the line (^) with zero spaces or more (\s*)
# * Has a '#' after them (#)
end
# And that's it!
exit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment