Created
January 22, 2011 20:17
-
-
Save jacegu/791428 to your computer and use it in GitHub Desktop.
A little example to illustrate how mixins work in Ruby
This file contains hidden or 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
module ModuleExample | |
def self.hello_world | |
puts 'This is a static hello world from a module' | |
end | |
def hello_world | |
puts 'This is a non static hello world from a module' | |
end | |
end | |
class MixedOne | |
include ModuleExample | |
end | |
mixed_class_instance = MixedOne.new | |
mixed_class_instance.hello_world | |
ModuleExample::hello_world | |
begin | |
MixedOne::hello_world | |
rescue NoMethodError | |
puts 'The static hello world is only avaliable within the module' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment