Sunday, 11 August 2013

how do I get ruby to -really- reload my class code?

how do I get ruby to -really- reload my class code?

Got some code in ruby that looks like (method in the Product class):
def merge_prices_with_suppliers(suppliers)
data = []
phs = self.prices
suppliers_in = phs.map { |ph| ph.supplier_id}.uniq()
for serv in suppliers_in
logger.debug serv
data_for_supplier = phs.select{|ph| ph.supplier_id== serv}
debugger
s = (suppliers.select{|s| s.id.to_s == serv }[0])
if s.nil? || s.name.nil?
name = "none"
else
name = s.name
end
logger.debug "#{name} #{serv}"
data.push([name, data_for_supplier.map{|ph| {date: ph.date, amount:
ph.amount} }])
end
data
end
I'm reloading and re-running this with:
reload! and g = Product.by_name( 'thenamehere') and
g.merge_prices_with_suppliers(suppliers)
OK so I make some changes because the select statement isn't working
correctly. Then I reload!. When I reload and redo the "get" of the object,
the new code is not present. The by_name code is pretty simple:
Game.where(name: name).first (using mongoid). I've also tried reload! on a
line by itself, no luck. I've tried setting the object to nil before
reloading with no luck.
Why is reload! not actually reloading my code? I've read other questions
on here about this issue but they didn't help.

No comments:

Post a Comment