Created
July 9, 2024 12:52
-
-
Save wyodeb/76a0173e9f3f0aaed350aa0662b8e23c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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