Skip to content

Instantly share code, notes, and snippets.

@koraktor
Created October 13, 2010 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save koraktor/623674 to your computer and use it in GitHub Desktop.
Save koraktor/623674 to your computer and use it in GitHub Desktop.
This demonstrates how to call constructors of multiple included modules in Ruby
#!/usr/bin/env ruby
#
# This code is free software; you can redistribute it and/or modify it under
# the terms of the new BSD License.
#
# Copyright (c) 2010, Sebastian Staudt
module HelloWorld
def initialize
puts 'Hello World!'
end
end
module Weather
def initialize(how)
puts "The weather is #{how}!"
end
end
class SeeYou
include HelloWorld
include Weather
def initialize(how, sometime)
HelloWorld.instance_method(:initialize).bind(self).call
Weather.instance_method(:initialize).bind(self).call(how)
puts "See you #{sometime}."
end
end
SeeYou.new('nice', 'soon')
Hello World!
The weather is nice!
See you soon.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment