Created
December 14, 2011 21:07
-
-
Save Amitesh/1478532 to your computer and use it in GitHub Desktop.
class mixin 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
require 'support/discussions' #require module | |
class Admin::DiscussionsController < ApplicationController | |
include Support::Discussions | |
def index | |
# Call class/static method | |
Admin::DiscussionsController.test() | |
#Call instance method | |
test2() | |
end | |
end | |
################ | |
# lib/support.rb | |
module Support | |
module Discussions | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def test | |
puts "haha" | |
end | |
end | |
def test2 | |
puts "hellooo" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment