Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@burke
Created September 24, 2019 19:32
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 burke/165a893f736926a047547d212c05ad8c to your computer and use it in GitHub Desktop.
Save burke/165a893f736926a047547d212c05ad8c to your computer and use it in GitHub Desktop.
require('yaml')
module Ohno
def self.replace_index(welp, index)
case welp
when String
welp == "$index" ? index : welp.gsub(/\$index/, index.to_s)
else
welp
end
end
end
class Loop
def self.allocate
k = Class.new(Array)
k.send(:define_method, :init_with) do |coder|
(coder.map['from']..coder.map['to']).each do |index|
push(Ohno.replace_index(coder.map['do'], index))
end
end
k.new
end
end
puts YAML.load(DATA.read).inspect
__END__
--- !ruby/object:Loop
from: 0
to: 3
do: $index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment