title: Ruby mixins looking for a best practice
body: <p>I'm writing Ruby Gem where I have <code>Connection</code> module for <code>Faraday</code> configuration</p>
  
  <pre><code>module Example
    module Connection
      private
  
      def connection
        Faraday.new(url: 'http://localhost:3000/api') do |conn|
          conn.request  :url_encoded             # form-encode POST params
          conn.response :logger                  # log requests to STDOUT
          conn.adapter  Faraday.default_adapter  # make requests with Net::HTTP
          conn.use      Faraday::Response::ParseJson
          conn.use      FaradayMiddleware::RaiseHttpException
        end
      end
    end
  end
  </code></pre>
  
  <p>Second module which makes API requests looks like this:</p>
  
  <pre><code>module Example
    module Request
      include Connection
  
      def get(uri)
        connection.get(uri).body
      end
  
      def post(url, attributes)
        response = connection.post(url) do |request|
          request.body = attributes.to_json
        end
      end
  
      def self.extended(base)
        base.include(InstanceMethods)
      end
  
      module InstanceMethods
        include Connection
  
        def put(url, attributes)
          response = connection.put(url) do |request|
            request.body = attributes.to_json
          end
        end
      end
    end
  end
  </code></pre>
  
  <p>Class <code>Cusomer</code> where I use <code>Request</code> looks like this:</p>
  
  <pre><code>module Example
    class Customer
      extend  Request
  
      attr_accessor :id, :name, :age
  
      def initialize(attrs)
        attrs.each do |key, value|
          instance_variable_set("@#{key}", value)
        end
      end
  
      def self.all
        customers = get('v1/customer')
        customers.map { |cust| new cust }
      end
  
      def save
        params = {
          id:   self.id,
          age:  self.age
          name: self.name,
        }
  
        put("v1/customers/#{self.id}", params)
      end
    end
  end
  </code></pre>
  
  <p>So here you see in <code>Customer#all</code> class method I'm calling <code>Request#get</code>  method which is available because I extended <code>Request</code> in <code>Customer</code>. then I'm using self.extended method in <code>Request</code> module to be make <code>Request#put</code> available in <code>Customer</code> class, so I have question is this good approach to use mixins like this, or do you have any suggestion?</p>