puts(Enumerator.new do |y|
loop { y.yield Array.new(rand(1..18)) { [*'a'..'z'].sample }.join }
end.lazy.reject(&IO.readlines('/usr/share/dict/words').method(:include?)).first(10).join(' '))
This generates "non-words", which are guaranteed not to exist in the (Unix) system dictionary, without using explicit assignment. First it creates a (lazy) generator object which yields random "words" of varying length. In Ruby, if you are calling a method with only one argument in an inner loop, you can avoid writing the loop explicitly, which is nice here because it also avoids the performance hit of reading the dictionary file repeatedly. The `method` method lets us pass an object-method pair, to be evaluated later, and the '&' there is a sort of cast-to-block, and you'll see that used in other contexts. So, at that point, we have a lazily-evaluated collection of lazily-filtered strings, and we can take an arbitrary number of these out and print them. [0] https://galliumos.org/
[1] https://github.com/dnschneid/crouton
[2] https://github.com/dnschneid/crouton#what-about-dem-crostinis-though
[3] https://spacevim.org/
I'm just still amazed that he figured it out that quickly; I really didn't tell him much about what had happened, and I'd hardly had time to leave the room before he'd solved it. What a jerk :)