Skip to content

Instantly share code, notes, and snippets.

@mgomes
Created October 20, 2023 13:31
Show Gist options
  • Save mgomes/e404081d6e6ae0bef48cd4fcc9219c49 to your computer and use it in GitHub Desktop.
Save mgomes/e404081d6e6ae0bef48cd4fcc9219c49 to your computer and use it in GitHub Desktop.
Method declaration with decoration in Ruby
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