Checking Join data for nil

Discussion in 'Ruby' started by Justin Kay, Jan 11, 2006.

  1. Justin Kay

    Justin Kay Guest

    So I have a join 1:0..1. If there is nothing in the child side I get an
    error when I say property.pdf.name that I can't access nil.name. But I
    can't seem to figure out how to check if pdf is nil or not before I call
    the .name function. If I test for property.pdf == nil it always comes
    back as nil, which it isn't.

    Any ideas?

    --
    Posted via http://www.ruby-forum.com/.
     
    Justin Kay, Jan 11, 2006
    #1
    1. Advertising

  2. On 1/11/06, Justin Kay <> wrote:
    > So I have a join 1:0..1. If there is nothing in the child side I get an
    > error when I say property.pdf.name that I can't access nil.name. But I
    > can't seem to figure out how to check if pdf is nil or not before I call
    > the .name function. If I test for property.pdf =3D=3D nil it always come=

    s
    > back as nil, which it isn't.
    >
    > Any ideas?


    I'm not exactly sure what you are doing, but in general to check for
    nil you can just use "if" like so (nil is false):

    if property.pdf
    puts property.pdf.name
    end

    Or if you want to be explicit:

    unless property.pdf.nil?
    puts property.pdf.name
    end

    If property.pdf is always nil, then you have some other bug in your code.

    Ryan
     
    Ryan Leavengood, Jan 11, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian Candler

    puts nil generates "nil\n"

    Brian Candler, Nov 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    120
  2. John Carter
    Replies:
    64
    Views:
    686
    Klaus Stein
    May 19, 2005
  3. ako...

    a == nil or a.nil?

    ako..., Nov 22, 2005, in forum: Ruby
    Replies:
    6
    Views:
    160
    Douglas Livingstone
    Nov 23, 2005
  4. Christoffer Sawicki
    Replies:
    5
    Views:
    280
    Christoffer Sawicki
    Sep 2, 2006
  5. Eero Saynatkari

    nil.to_s != "nil"

    Eero Saynatkari, Oct 27, 2006, in forum: Ruby
    Replies:
    11
    Views:
    249
    Gregory Brown
    Oct 28, 2006
Loading...

Share This Page