2
votes

Given the following code:

module Foo
  extend ActiveSupport::Concern

  module ClassMethods
    def foo
      puts 'foo'
    end
  end
end

class Bar
  include Foo
end

What I'd like to do is call Foo.foo instead of Bar.foo. Sometimes it feels more natural to call a class method on the original module, especially when the functionality has nothing to do with the included class and is better described along with the original module name.

1

1 Answers

5
votes

This seems like a code smell. Having said that, you can just have the Foo module extend itself with the class methods:

module Foo
  extend ActiveSupport::Concern

  module ClassMethods
    def foo
      puts 'foo'
    end
  end

  extend ClassMethods
end

class Bar
  include Foo
end

Bar.foo
Foo.foo