Last active
May 18, 2021 09:04
-
-
Save thenapking/d78e0a15f302d46dd5baa6a0232f12d2 to your computer and use it in GitHub Desktop.
Here's a neat example of metaprogramming using define_method rather than method_missing. Also a very neat use of each_with_index.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Something | |
%w(zero one two three four five six seven eight nine).each_with_index do |w,i| | |
define_method(w) { perform i } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment