another nil concern

Discussion in 'Ruby' started by Nasir Khan, Dec 24, 2008.

  1. Nasir Khan

    Nasir Khan Guest

    [Note: parts of this message were removed to make it a legal post.]

    irb(main):012:0> nil =~ /foo/
    => false

    Should'nt it return nil instead?

    BR
    nasir
     
    Nasir Khan, Dec 24, 2008
    #1
    1. Advertising

  2. Nasir Khan

    Peña, Botp Guest

    From: Nasir Khan [mailto:]=20
    # irb(main):012:0> nil =3D~ /foo/
    # =3D> false
    #=20
    # Should'nt it return nil instead?

    depends on the beholder.

    :~$ qri =3D~
    ---------------------------- Multiple choices:

    Gem::Dependency#=3D~, Gem::platform#=3D~, Object#=3D~,
    REXML::Light::Node#=3D~, RegAnd#=3D~, RegOr#=3D~, Regexp#=3D~, =
    String#=3D~

    :~$ qri object#=3D~
    --------------------------------Object#=3D~
    obj =3D~ other =3D> false
    --------------------------------
    Pattern Match---Overridden by descendents (notably Regexp and
    String) to provide meaningful pattern-match semantics.


    so you probably want,

    > /foo/ =3D~ nil

    =3D> nil


    and if failing is divine, try #match

    > /foo/.match nil

    =3D> nil

    > nil.match /foo/

    NoMethodError: undefined method `match' for nil:NilClass
     
    Peña, Botp, Dec 24, 2008
    #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:
    113
  2. John Carter
    Replies:
    64
    Views:
    648
    Klaus Stein
    May 19, 2005
  3. ako...

    a == nil or a.nil?

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

    nil.to_s != "nil"

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

Share This Page