title: Two extended classes - one works and the other doesn't
body: <p>I have had some difficulties in using extended classes in rails, in particular extending the Matrix class - and I have also asked some questions related to this:</p>
  
  <p><a href="https://stackoverflow.com/questions/9070443/am-i-extending-this-inbuilt-ruby-class-correctly">Am I extending this inbuilt ruby class correctly</a></p>
  
  <p><a href="https://stackoverflow.com/questions/9053203/using-custom-functions-in-rails-app">Using custom functions in rails app</a></p>
  
  <p><a href="https://stackoverflow.com/questions/9052860/where-do-i-put-this-matrix-class-in-my-rails-app">Where do I put this matrix class in my rails app</a></p>
  
  <p>In general the answers have been around autoloading in rails 3. <strong>However, when I extend 'Math' new functions work, when I extend 'Matrix' new functions don't work - even if I treat them in the same way</strong></p>
  
  <p>I've tried many iterations and change module names, requires, autoloads but here are my latest key files:</p>
  
  <p>application.rb:</p>
  
  <pre><code>require File.expand_path('../boot', __FILE__)
  
  require 'rails/all'
  require 'matrix'
  
  # If you have a Gemfile, require the gems listed there, including any gems
  # you've limited to :test, :development, or :production.
  Bundler.require(:default, Rails.env) if defined?(Bundler)
  
  module SimpleFixed
    class Application &lt; Rails::Application
      # Settings in config/environments/* take precedence over those specified here.
      # Application configuration should go into files in config/initializers
      # -- all .rb files in that directory are automatically loaded.
  
      # Custom directories with classes and modules you want to be autoloadable.
      # **I have tried all these autoload variants**
      #  config.autoload_paths += %W(#{config.root}/extras)
      #  config.autoload_paths += %W(#{config.root}/lib)
      #  config.autoload_paths += Dir["#{config.root}/lib/**/"]
      #  config.autoload_paths &lt;&lt; "#{Rails.root}/lib"
        config.autoload_paths &lt;&lt; "#{::Rails.root.to_s}/lib" # &lt;-- set path
        require "extend_matrix" # &lt;-- forcibly load your matrix extension
  
  *other standard code here*
  </code></pre>
  
  <p>lib/extend_math.rb</p>
  
  <pre><code>module Math
    class &lt;&lt; self
  
      def cube_it(num)
        num**3
      end
  
      def add_five(num)
        num+5
      end
  
    end
  end
  </code></pre>
  
  <p>lib/extend_matrix.rb</p>
  
  <pre><code>module Extend_matrix **An error is raised if I call this Matrix**
  
    class Matrix
  
      def symmetric?
        return false if not square?
        (0 ... row_size).each do |i|
          (0 .. i).each do |j|
            return false if self[i,j] != self[j,i]
          end
        end
        true
      end
  
      def cholesky_factor
        raise ArgumentError, "must provide symmetric matrix" unless symmetric?
        l = Array.new(row_size) {Array.new(row_size, 0)}
        (0 ... row_size).each do |k|
          (0 ... row_size).each do |i|
            if i == k
              sum = (0 .. k-1).inject(0.0) {|sum, j| sum + l[k][j] ** 2}
              val = Math.sqrt(self[k,k] - sum)
              l[k][k] = val
            elsif i &gt; k
              sum = (0 .. k-1).inject(0.0) {|sum, j| sum + l[i][j] * l[k][j]}
              val = (self[k,i] - sum) / l[k][k]
              l[i][k] = val
            end
          end
        end
        Matrix[*l]
      end
  
    end
  
  end
  </code></pre>
  
  <p>my view page:</p>
  
  <pre><code>&lt;%= Math.add_five(6) %&gt; **works*
  
  &lt;%= Matrix[[25,15,-5],[15,18,0],[-5,0,11]].cholesky_factor %&gt; **doesn't work**
  </code></pre>
  
  <p>Could it be because Math is a Module in ruby but Matrix is a class? If so, how do I correct for this?</p>