Following code is only for testing purposes
controller class
def show
@game = Game.find(params[:id])
matrix = [
[':yes', ':No', ':none'],
[':yes', ':No',' :Yes'],
[':No', ':Yes', ':none'],
]
@game.matrix = ::Gamer.new(matrix).next
@game.save!()
...
end
Another class in lib folder
class Gamer
@@current_value
def initialize(args_value)
@@current_value = Marshal.load(Marshal.dump(args_value))
end
def next
prev_state = Marshal.load(Marshal.dump(@@current_value))
for row in prev_state
for item in row
...
#making changes into `@@current_value`
...
end
end
return @@current_value
end
Whenever I check the value of gamer.matrix
it returns null
everytime. If i replace return
from return @@current_value
with return @@prev_state
I am getting the exact value which I passed to this function. That means my controller
is able to call this class method.
What I am doing wrong here?
Aucun commentaire:
Enregistrer un commentaire