Advertisements

Tom Link wrote:
>> #Apparently, the simple fact of checking this keeps Ruby from raising
>> #a NoMethodError when those entries don't exist
>>
>
> Entry is a hash I presume?
>
> a = {:a => 1, :b => 2}
>
> a[:a]
> => 1
> a[:x]
> nil
>
Entry is a very big hash and I use those values later - if I don't run
those three lines, I'll get a crash, but if I run those three lines,
using those values is fine even if they don't exist... Oh -- is that
because it -creates- the key-value pair when I look at it ?

On Tue, Dec 16, 2008 at 3:39 PM, Aldric Giacomoni
<"aldric[remove]"@trevoke.net> wrote:
> Tom Link wrote:
> Entry is a very big hash and I use those values later - if I don't run those
> three lines, I'll get a crash, but if I run those three lines, using those
> values is fine even if they don't exist... Oh -- is that because it
> -creates- the key-value pair when I look at it ?

If the code you posted is really the only relevant code and entry is a
Hash, then no.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!