• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Take & Drop (MOTM 2010.04)
 

Take & Drop (MOTM 2010.04)

on

  • 488 views

Ruby Method of the Month 2010.04. Lightning talk for the Columbus Ruby Brigade.

Ruby Method of the Month 2010.04. Lightning talk for the Columbus Ruby Brigade.

Statistics

Views

Total Views
488
Views on SlideShare
486
Embed Views
2

Actions

Likes
0
Downloads
2
Comments
0

1 Embed 2

http://www.linkedin-ei2.com 2

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Take & Drop (MOTM 2010.04) Take & Drop (MOTM 2010.04) Presentation Transcript

  • MOTM: Take & Drop Kevin Munc — @muncman
  • Taking
  • take & take_while take(n) gives you the first n elements take_while { |elem| block } gives you elements until the block condition is nil or false Works on Array and Enumerable
  • take uhray = [0,1,2,3,4,5,6,7,8,9] uhray.take(5) => [0,1,2,3,4]
  • take uhray = [0,1,2,3,4,5,6,7,8,9] uhray.take(5) => [0,1,2,3,4] uhray = [] uhray.take(5) => []
  • take_while uhray = [0,1,2,3,4,5,6,7,8,9] uhray.take_while { |item| item < 6 } => [0,1,2,3,4,5]
  • take_while uhray = [0,1,2,3,4,5,6,7,8,9] uhray.take_while { |item| item < 6 } => [0,1,2,3,4,5] uhray.take_while { |item| item > 6 } => []
  • Dropping
  • drop & drop_while drop(n) gives you all elements after the first n elements drop_while { |elem| block } gives you all elements starting when the block condition is nil or false Works on Array and Enumerable
  • drop uhray = [0,1,2,3,4,5,6,7,8,9] uhray.drop(5) => [5,6,7,8,9]
  • drop uhray = [0,1,2,3,4,5,6,7,8,9] uhray.drop(5) => [5,6,7,8,9] uhray = [] uhray.drop(5) => []
  • drop_while uhray = [0,1,2,3,4,5,6,7,8,9] uhray.drop_while { |item| item < 6 } => [6,7,8,9]
  • drop_while uhray = [0,1,2,3,4,5,6,7,8,9] uhray.drop_while { |item| item < 6 } => [6,7,8,9] uhray.drop_while { |item| item > 6 } => [0,1,2,3,4,5,6,7,8,9]
  • Questions? Built on an iPad Photo Credits http://www.flickr.com/photos/stevewall/802936876/ http://www.flickr.com/photos/z6p6tist6/3967592710/ http://www.flickr.com/photos/whosdadog/3652663745/