Skip to content

Instantly share code, notes, and snippets.

@hlegius
Created September 17, 2015 17:21
Show Gist options
  • Save hlegius/1486e344b5c9728c4662 to your computer and use it in GitHub Desktop.
Save hlegius/1486e344b5c9728c4662 to your computer and use it in GitHub Desktop.
Mixins & Self
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