Skip to content

Instantly share code, notes, and snippets.

@yitznewton
Created January 14, 2015 14:54
Show Gist options
  • Select an option

  • Save yitznewton/35061bc05ddcaf159a94 to your computer and use it in GitHub Desktop.

Select an option

Save yitznewton/35061bc05ddcaf159a94 to your computer and use it in GitHub Desktop.
Mixins: good and evil
# evil
module MoarMethods
def foo
end
def bar
end
end
class TooManyMethods
include MoarMethdods
def baz
end
def quux
end
end
# good
module Loggable
def log_method(method_name)
# metaprogramming magic that taps messages to the implementing class and logs stuff
end
end
class Beast
include Loggable
log_method :roar
def roar
output.append('rrr!')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment