Created
October 13, 2010 08:29
-
-
Save koraktor/623674 to your computer and use it in GitHub Desktop.
This demonstrates how to call constructors of multiple included modules 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
#!/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') |
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
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