Skip to content

Instantly share code, notes, and snippets.

@ethnt
Created July 10, 2015 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethnt/c8f76a2d8aa26b0c4d27 to your computer and use it in GitHub Desktop.
Save ethnt/c8f76a2d8aa26b0c4d27 to your computer and use it in GitHub Desktop.
Include arbitrary modules with Ruby.
# Use this class to test an arbitrary module.
class Harness
def initialize(_module)
self.class.include _module
end
end
###
# The module being tested
module ToBeTested
def foo
"foo!"
end
end
harness = Harness.new(ToBeTested)
harness.foo # => "foo!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment