Created
September 17, 2015 17:21
-
-
Save hlegius/1486e344b5c9728c4662 to your computer and use it in GitHub Desktop.
Mixins & Self
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 Foo | |
def save | |
puts 'in save' | |
end | |
end | |
module Foo | |
def self.included(resource) | |
resource.extend ClassMethods | |
end | |
def initialize | |
class << self; lol('haha'); end | |
end | |
module ClassMethods | |
def find | |
puts 'find' | |
lol('hehe') | |
end | |
end | |
end | |
class Bar | |
include Foo | |
def self.lol(atr) | |
puts "in lol #{atr}" | |
end | |
end | |
Bar.find | |
b = Bar.new | |
b.save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment