# Ruby porting question - dynamic methods

**URL:** <https://forum.crystal-lang.org/t/ruby-porting-question-dynamic-methods/3927>\
**Category:** Help & Support\
**Created:** [October 11, 2021, 1:00am UTC](https://forum.crystal-lang.org/t/ruby-porting-question-dynamic-methods/3927 "2021-10-11T01:00:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ggt](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ggt/32/1412_2.png) [@ggt](https://forum.crystal-lang.org/u/ggt)\
**Post date:** [October 11, 2021, 1:00am UTC](https://forum.crystal-lang.org/t/ruby-porting-question-dynamic-methods/3927/1 "2021-10-11T01:00:40Z")

</div>

Hi, I’m attempting to port a ruby gem to a shard, but I’ve run into a block, specifically how to do the following in crystal:

```auto
ops = %w[fill stroke fill_and_stroke]
    shapes = %w[
      line_to curve_to rectangle rounded_rectangle line horizontal_line
      horizontal_rule vertical_line curve circle_at circle ellipse_at ellipse
      polygon rounded_polygon rounded_vertex
    ]

    ops.product(shapes).each do |operation, shape|
      class_eval <<-METHOD, __FILE__ , __LINE__ + 1
        def #{operation}_#{shape}(*args) # def fill_polygon(*args)
          #{shape}(*args) # polygon(*args)
          #{operation} # fill
        end # end
      METHOD
    end

```

I thought I might be able to use a macro, but my attempts so far have been unsuccessful, mainly because it looks like macros always want literal args not Vars.(?)  
Any suggestions would be most helpful.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [October 11, 2021, 1:11am UTC](https://forum.crystal-lang.org/t/ruby-porting-question-dynamic-methods/3927/2 "2021-10-11T01:11:21Z")

</div>

```auto
{% for op in %w[fill stroke fill_and_stroke] %}
  {% for shape in %w[
                    line_to curve_to rectangle rounded_rectangle line horizontal_line
                    horizontal_rule vertical_line curve circle_at circle ellipse_at ellipse
                    polygon rounded_polygon rounded_vertex
                  ] %}
    
    def {{op.id}}_{{shape.id}}(*args)
      {{shape.id}}(*args)
      {{op.id}}
    end
  {% end %}
{% end %}

```

This should do it.

---

<div class="post-metadata">

**Author:** ![ggt](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/ggt/32/1412_2.png) [@ggt](https://forum.crystal-lang.org/u/ggt)\
**Post date:** [October 11, 2021, 2:22am UTC](https://forum.crystal-lang.org/t/ruby-porting-question-dynamic-methods/3927/3 "2021-10-11T02:22:50Z")

</div>

Ah yes, that makes sense. Thank you!
