It is a common practive in Ruby. Right now would be done for exercise and experimentation, but it would make a lot of sense when you don't have only 1 switch statement and your code grows in complexity.
I don't know about Ruby, but in fact some languages don't even have switch statements, for example, Python.
Creating a code that'll "know" which function to run without you telling it to with a direct statement is nice, but always try to think about some junior devs that might join your team. I had this phase of writing super complex code that only senior developers understood. But I quickly backed away, as I wasn't able to go on vacation, since I was the one person in the current team that understood how it all worked.
(But I quickly backed away, as I wasn't able to go on vacation, since I was the one person in the current team that understood how it all worked) :-D
Yes, I guess everything has its downside.
I think using metaprogramming sometimes is literally an alternative to using design patterns. For example the Factory Design Pattern allows you dinamically create objects, but you could solve the same problem with inheritance and metaprogramming
but the code would me much harder to read and does not make sense in Frontend Development.
The good thing is that Ecmascript now is really advanced and you are free to do anything with it. It is very good for Frontend, but also backend development.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Why would you obscure such a simple statement with a loop? It would be shorter, true, but more complex to the reader.
It is a common practive in Ruby. Right now would be done for exercise and experimentation, but it would make a lot of sense when you don't have only 1 switch statement and your code grows in complexity.
I don't like switch or if statements
keithcirkel.co.uk/metaprogramming-...
I don't know about Ruby, but in fact some languages don't even have
switch
statements, for example, Python.Creating a code that'll "know" which function to run without you telling it to with a direct statement is nice, but always try to think about some junior devs that might join your team. I had this phase of writing super complex code that only senior developers understood. But I quickly backed away, as I wasn't able to go on vacation, since I was the one person in the current team that understood how it all worked.
(But I quickly backed away, as I wasn't able to go on vacation, since I was the one person in the current team that understood how it all worked) :-D
Yes, I guess everything has its downside.
I think using metaprogramming sometimes is literally an alternative to using design patterns. For example the Factory Design Pattern allows you dinamically create objects, but you could solve the same problem with inheritance and metaprogramming
alligator.io/js/factory-pattern/
but the code would me much harder to read and does not make sense in Frontend Development.
The good thing is that Ecmascript now is really advanced and you are free to do anything with it. It is very good for Frontend, but also backend development.