Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created February 17, 2026 19:15
Show Gist options
  • Select an option

  • Save havenwood/51b8c77710b6ce25a47d82d7f62f0852 to your computer and use it in GitHub Desktop.

Select an option

Save havenwood/51b8c77710b6ce25a47d82d7f62f0852 to your computer and use it in GitHub Desktop.
An example Enumerable ARGV/STDIN for #ruby IRC
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