Created
September 24, 2019 19:32
-
-
Save burke/165a893f736926a047547d212c05ad8c to your computer and use it in GitHub Desktop.
This file contains 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
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