From: Gavin Sinclair Date: 2010-07-17T21:20:04+09:00 Subject: Re: Pstore confusion for a beginner > > Questions: > 1. In this line of code "store[:this] ||= Faunadb.new("")" , what is the > double pipe equal sign doing? Does it just indicate that the :this > symbol points to the new Faunadb instance? Why is the double pipe thingy > not used on the "copy back" code fragment? Would I use the symbol to > just keep track of what is stored? I know :this is pretty goofy. > a ||= b is short for "a = a || b", just like "a += b" is short for "a = a + b". || is pronounced "or" (note: Ruby has two similar operators || and 'or' with an important difference -- see any Ruby reference). a ||= b is equivalent to the following code if a   # nothing happens else   a = b end So store[:this] ||= ...  is saying "if store[:this] doesn't already exist, set it to...". > > 2. In this line of code fdb1=store[:this] from the restore, I noticed > that it is necessary to have the same symbol :this, in this code > fragment, as it was in the prior fragment, because I get an error > otherwise. Is this correct? > A PStore object is like a hash. Imagine you used a hash to store some name and address details. hash = {} hash[:name] = "John Smith" hash[:address] = "..." When you wanted to retrieve the name and address, you'd need to use the same keys :name and :address, wouldn't you? puts hash[:name] puts hash[:address] Hope this helps, Gavin