As I understand it, simply extending ActiveSupport::Concern in a module automatically adds as class methods anything that’s in the module ClassMethods.
require 'active_support/concern'
module LibraryUtils
extend ActiveSupport::Concern
def add_game(game)
end
def remove_game(game)
end
module ClassMethods
def search_by_game_name(name)
end
def load_game_list
end
end
end
class Game
include LibraryUtils
end
# Then this works
game = Game.new
game.add_game "NewGame"
Game.load_game_list
I could also use:
included do
load_game_list
end
and it would add ‘load_game_list’ as a class method. I see that I can used ‘indluded’ to add a method that’s not part of a ClassMethods module; is there any other difference and why would I use one over the other?