Skip to content

Instantly share code, notes, and snippets.

@luke-gru
Forked from koraktor/Output:
Created August 21, 2011 16:12
Show Gist options
  • Save luke-gru/1160800 to your computer and use it in GitHub Desktop.
Save luke-gru/1160800 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