Skip to content

Instantly share code, notes, and snippets.

@Iainmon
Last active July 16, 2024 01:10
Show Gist options
  • Select an option

  • Save Iainmon/2beb2a75c20f78408e39529db6a6dc74 to your computer and use it in GitHub Desktop.

Select an option

Save Iainmon/2beb2a75c20f78408e39529db6a6dc74 to your computer and use it in GitHub Desktop.
macro for(definition, condition, incrimentation, &block)
{{definition}}
while {{condition}}
{{block.body}}
{{incrimentation}}
end
end
macro for(expr)
({{expr.args.first.args.first}}).each do |{{expr.name.id}}|
{{expr.args.first.block.body}}
end
end
# Regular for loop
for x = 0, x < 5, x += 1 do
puts x
end
# For-in loop
for x in 1..5 do
puts x
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment