Created
May 23, 2012 13:20
-
-
Save andreydjason/2775207 to your computer and use it in GitHub Desktop.
Ruby Codings :-)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: utf-8 | |
# Ruby | |
# | |
# to run in a Rails environment (add the line below) | |
# require './config/environment' | |
# | |
# An example of how select the last item of an array that's not nil | |
def select_last_not_nil(options) | |
item = nil | |
while item.nil? | |
item = options.pop | |
end | |
item | |
end | |
puts select_last_not_nil([1,2,nil,4,5,nil,nil]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment