Skip to content

Instantly share code, notes, and snippets.

@wyodeb
Created July 9, 2024 12:52
Show Gist options
  • Save wyodeb/76a0173e9f3f0aaed350aa0662b8e23c to your computer and use it in GitHub Desktop.
Save wyodeb/76a0173e9f3f0aaed350aa0662b8e23c to your computer and use it in GitHub Desktop.
class MyClass
def self.create_methods(methods)
methods.each do |method_name|
define_method(method_name) do
"This is method #{method_name}"
end
end
end
create_methods([:method1, :method2])
obj = MyClass.new
puts obj.method1 # Outputs: "This is method method1"
puts obj.method2 # Outputs: "This is method method2"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment