Skip to content

Instantly share code, notes, and snippets.

@Amitesh
Created December 14, 2011 21:07
Show Gist options
  • Save Amitesh/1478532 to your computer and use it in GitHub Desktop.
Save Amitesh/1478532 to your computer and use it in GitHub Desktop.
class mixin in ruby
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