SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: include?

Hybrid View

  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,582
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    include?

    Doesn't the include?? return a boolean value?
    http://apidock.com/ruby/Array/include%3F
    Can someone explain how a value of 1 is the result in the last statement?


    include.jpg
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,343
    Mentioned
    179 Post(s)
    Tagged
    9 Thread(s)
    detect returns the first item in the range for which the block returns TRUE.

    Your example:

    Code Ruby:
    (1..10).detect{|i| (1..10).include?(i*3)}
    => 1

    returns 1 because that is the first item in the range (1..10) that returns TRUE for the expression (1..10).include?(i*3).

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,582
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    thanksss
    "Oh, and Jenkins--apparently your mother died this morning."


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •