Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Created November 12, 2025 22:26
Show Gist options
  • Select an option

  • Save amirrajan/6ab6639383edcc44b7911858c4c1b8bc to your computer and use it in GitHub Desktop.

Select an option

Save amirrajan/6ab6639383edcc44b7911858c4c1b8bc to your computer and use it in GitHub Desktop.
# repetition specifies:
# token |   description        |
# ------+----------------------+
# $(),  | each comma delemited |
# $():, | each kwarg delemited |
# $()*  | each                 |
#
# intrinsic macros
# $to_s!
# $to_ivar!
# $to_kwarg!
# $to_sym!
# $local!

def $make_class!($name, $($attr_accessors),*)
  class $name
    def initialize($($to_kwarg!($attr_accessors)),*)
      $(
        $to_ivar!($attr_accessors) = $to_s!($attr_accessors)
      )*
    end
  end
end

$make_class!(Person, :first_name, :last_name)

# generates

class Person
  def initialize(first_name:, last_name:)
    @first_name = first_name
    @last_name = last_name
  end
end
def $each!($collection, **$($name, $block))
  $local!(os) = $collection
  $local!(l) = $collection.length
  $local!(i) = 0
  while $local!(i) < $local!(l)
    $name = $local!(os)[i]
    $block
    $local(i) += 1
  end
end

$each!(bullets,
       bullet: begin
                 if Geometry.intersect_rect?(bullet, player)
                   bullet.killed_at = Kernel.tick_count
                 end
               end)

# generates
__uuid_os__ = bullets
__uuid_l__  = bullets.length
__uuid_i__  = 0

while __uuid_i__ < __uuid_l__
  bullet = __uuid_os__[i]
  begin
    if Geometry.intersect_rect?(bullet, player)
      bullet.killed_at = Kernel.tick_count
    end
  end
  __uuid_i__ += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment