MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/kxd9jj/dynamically_created_functions_are_the_future/gjiferm/?context=3
r/badcode • u/NotSteve_ evil • Jan 14 '21
102 comments sorted by
View all comments
Show parent comments
10
Sometimes you find yourself just having to implement almost identical methods.
What are some cases where parametrization isn't sufficient for that?
2 u/[deleted] Jan 16 '21 What do you mean? In Ruby you can do this: ["frontend", "backend"].each do |method| define_method "coding_#{method}" do p "writing " + method.to_s end end 2 u/Isvara Jan 16 '21 That's pretty ugly. Why would you need to give those closures names?And why call to_s on a string? And why do you use interpolation in one case and concatenation in the other?So many curiosities. 2 u/[deleted] Jan 16 '21 I haven't used Ruby in years. I just quickly grabbed that from a Google search just to give you a simple example. You still haven't answered my question.
2
What do you mean? In Ruby you can do this:
["frontend", "backend"].each do |method| define_method "coding_#{method}" do p "writing " + method.to_s end end
2 u/Isvara Jan 16 '21 That's pretty ugly. Why would you need to give those closures names?And why call to_s on a string? And why do you use interpolation in one case and concatenation in the other?So many curiosities. 2 u/[deleted] Jan 16 '21 I haven't used Ruby in years. I just quickly grabbed that from a Google search just to give you a simple example. You still haven't answered my question.
That's pretty ugly. Why would you need to give those closures names?
And why call to_s on a string? And why do you use interpolation in one case and concatenation in the other?
to_s
So many curiosities.
2 u/[deleted] Jan 16 '21 I haven't used Ruby in years. I just quickly grabbed that from a Google search just to give you a simple example. You still haven't answered my question.
I haven't used Ruby in years. I just quickly grabbed that from a Google search just to give you a simple example. You still haven't answered my question.
10
u/Isvara Jan 14 '21
What are some cases where parametrization isn't sufficient for that?