-
-
Save sai43/da59ff592ad7734a6373 to your computer and use it in GitHub Desktop.
Module - Include or Extend? and Mixin: http://surya.rajtripathi.com/2013/12/module-include-or-extend-and-mixin.html
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
module InstanceModule | |
def track | |
"Tracking todo: #{self.name}" | |
end | |
end | |
module ClassModule | |
def class_name | |
"Tracking class: #{self.name}" | |
end | |
end | |
class Todo | |
include InstanceModule | |
extend ClassModule | |
attr_reader :name | |
def initialize(task_name) | |
@name = task_name | |
end | |
end | |
t = Todo.new('read a blog') | |
puts t.track | |
puts Todo.class_name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment