I'm trying to create an attribute of the class that will be an array of similarity among users. Is there something wrong with this construction? Is there a better way to do it?
class Usuario < ActiveRecord::Base
require 'matrix'
@@similaridade = Matrix.build( self.all.size, self.all.size)
{|x,y| similaridade_com self.find(x + 1), self.find(y + 1) }
def self.similaridade
@@similaridade
end
private
def similaridade_com(usuario1, usuario2)
...
end
end
When I am calling Usuario.similaridade
on rails console
it is giving the error NoMethodError: undefined method 'similarity_com' for #Class: 0x007ff55873cad0