Skip to content

Instantly share code, notes, and snippets.

@jacegu
Created January 22, 2011 20:17
Show Gist options
  • Save jacegu/791428 to your computer and use it in GitHub Desktop.
Save jacegu/791428 to your computer and use it in GitHub Desktop.
A little example to illustrate how mixins work in Ruby
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