Created
October 5, 2017 09:57
-
-
Save oinak/d5662e6d82b8a86604a371cdd2dfde07 to your computer and use it in GitHub Desktop.
XKCD approved password generator (https://www.xkcd.com/936/)
This file contains hidden or 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
| # https://www.xkcd.com/936/ | |
| module Clave | |
| extend self | |
| def run | |
| puts((1..4).map { safe_words.sample }.join(" ")) | |
| end | |
| private | |
| SAFE_SET = /\A[A-Za-z]+\Z/.freeze | |
| def safe_words | |
| @safe ||= words.select{ |w| SAFE_SET.match(w) } | |
| end | |
| def words | |
| @words ||= File.read("/usr/share/dict/spanish").split("\n") | |
| end | |
| end | |
| Clave.run if __FILE__ == $PROGRAM_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment