Created
February 17, 2026 19:15
-
-
Save havenwood/51b8c77710b6ce25a47d82d7f62f0852 to your computer and use it in GitHub Desktop.
An example Enumerable ARGV/STDIN for #ruby IRC
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
| Words = Data.define(:argv, :stdin) | |
| class Words | |
| STDIN_ARGV = ["-"].freeze | |
| include Enumerable | |
| def initialize(argv: ARGV, stdin: $stdin) = super | |
| def each(&) | |
| return enum_for(__method__) unless block_given? | |
| return argv.each(&) unless argv == STDIN_ARGV | |
| stdin.each_line.lazy.flat_map(&:split).each(&) | |
| end | |
| end | |
| Words.new(ARGV).each { |word| # ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment