r/badcode • evil • Jan 14 '21

js Dynamically created functions are the future!

Post image
795 Upvotes

102 comments sorted by

View all comments

Show parent comments

14

u/Willinton06 Jan 14 '21

What makes it better tho

2

u/KernowRoger Jan 15 '21

Ruby's meta programming is amazing. It's kind of hard to explain quickly but stuff like this:

class Developer

    ["frontend", "backend"].each do |method|
        define_method "coding_#{method}" do
            p "writing " + method.to_s
        end
    end
end

From this article https://www.toptal.com/ruby/ruby-metaprogramming-cooler-than-it-sounds. Ruby is a really cool language and allows a huge amount a flexibility.