1
I’m trying to create an attribute of the class that will be an array of similarities between users. Is there something wrong with this construction? There’s 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’m calling Usuario.similaridade
in the rails console
is making the mistake Nomethoderror: Undefined method `similaridade_com' for #Class:0x007ff55873cad0
Ever tried to put
self.
in front of the method call?– user7261
You are using a class variable (@@similarity) that when initialized uses an instance method (similarity_com). Have you tried Andrey’s tip?
– Olivictor