[rspec-users] variable strange change

Zhenning Guan lists at ruby-forum.com
Wed Sep 15 04:19:20 EDT 2010


class User
  has_many :mads

  def mad
    Mad.find_by_user_id(id)
  end
end

class God
  belongs_to :mad
  belongs_to :user
  belongs_to :sender, :class_name => "User", :foreign_key => "sender_id"

  def strange_change!
    God.transaction do
      puts mad.nil?    #the first time put is false
      if mad.nil?
        puts 'some thing exctue here'           #no puts anything
        mad = you.mad
      end
      puts mad.nil?    #the second time put is true
    end
  end
end

why the mad will become nil?
-- 
Posted via http://www.ruby-forum.com/.


More information about the rspec-users mailing list