RCR: String#contain? and Array#contain?

Discussion in 'Ruby' started by Roger Pack, Sep 23, 2010.

  1. Roger Pack

    Roger Pack Guest

    Every time I have to guess from memory whether to use "contain?" or
    "include?" within arrays and strings, I always guess wrong (the right
    answer is only "include?" BTW).
    Since ruby typically allows multiple ways of doing things, consider this
    a feature request to add contain? to both String and Array.

    Any feedbacks to this idea?
    Thanks.
    -r
    --
    Posted via http://www.ruby-forum.com/.
     
    Roger Pack, Sep 23, 2010
    #1
    1. Advertising

  2. Roger Pack

    Intransition Guest

    On Sep 23, 4:32=A0pm, Roger Pack <> wrote:
    > Every time I have to guess from memory whether to use "contain?" or
    > "include?" within arrays and strings, I always guess wrong (the right
    > answer is only "include?" BTW).
    > Since ruby typically allows multiple ways of doing things, consider this
    > a feature request to add contain? to both String and Array.
    >
    > Any feedbacks to this idea?


    alias :contain?, :include?

    That's what you mean?
     
    Intransition, Sep 24, 2010
    #2
    1. Advertising

  3. On 23 September 2010 22:32, Roger Pack <> wrote:
    > Every time I have to guess from memory whether to use "contain?" or
    > "include?" within arrays and strings, I always guess wrong (the right
    > answer is only "include?" BTW).
    > Since ruby typically allows multiple ways of doing things, consider this
    > a feature request to add contain? to both String and Array.
    >
    > Any feedbacks to this idea?
    > Thanks.
    > -r
    > --


    You might want to read the thread about the "in" operator on ruby-core.
    Something like:
    e.in? ary
    e in ary
    give more sense to me than any enum.method? e
     
    Benoit Daloze, Sep 24, 2010
    #3
  4. Roger Pack

    Roger Pack Guest

    > e in ary
    > give more sense to me than any enum.method? e


    True, though at times I would find it convenient to use the enum method,
    like

    strin.each_line { |line|
    if line.contain? 'abc'
    print 'yes'
    end
    }

    > alias :contain?, :include?
    > That's what you mean?


    Yep, but just not me having to do it :)

    -r
    --
    Posted via http://www.ruby-forum.com/.
     
    Roger Pack, Sep 28, 2010
    #4
    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. Peter B. Steiger

    Can a static array contain a dynamic array of pointers?

    Peter B. Steiger, Apr 19, 2004, in forum: C Programming
    Replies:
    8
    Views:
    2,099
    Dave Thompson
    Apr 26, 2004
  2. Simon Strandgaard

    [rcr] String#first / String#last

    Simon Strandgaard, Oct 24, 2004, in forum: Ruby
    Replies:
    29
    Views:
    240
    Brian Candler
    Oct 26, 2004
  3. Simon Strandgaard

    [rcr] Array#join non string arguments

    Simon Strandgaard, Feb 19, 2005, in forum: Ruby
    Replies:
    14
    Views:
    196
    Alexander Kellett
    Feb 20, 2005
  4. Simon Strandgaard

    [RCR] array or with non-array

    Simon Strandgaard, Aug 2, 2005, in forum: Ruby
    Replies:
    27
    Views:
    244
    Nikolai Weibull
    Sep 1, 2005
  5. Jason Carlton
    Replies:
    11
    Views:
    248
    Dr J R Stockton
    Dec 8, 2009
Loading...

Share This Page