Skip to content

Instantly share code, notes, and snippets.

@thenapking
Last active May 18, 2021 09:04
Show Gist options
  • Save thenapking/d78e0a15f302d46dd5baa6a0232f12d2 to your computer and use it in GitHub Desktop.
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.
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