Created
October 20, 2023 13:31
-
-
Save mgomes/e404081d6e6ae0bef48cd4fcc9219c49 to your computer and use it in GitHub Desktop.
Method declaration with decoration in Ruby
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
module MethodDetector | |
def option_stack | |
@option_stack ||= [] | |
end | |
def method_added(method_name) | |
unless option_stack.empty? | |
option = option_stack.pop | |
puts "You added the option '#{option}' to the method: #{method_name}" | |
end | |
super | |
end | |
def add_option(option_name) | |
option_stack << option_name | |
end | |
end | |
class Vehicle | |
extend MethodDetector | |
add_option :logging | |
def to_s | |
end | |
add_option :async | |
def acquire | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment