Skip to content

Instantly share code, notes, and snippets.

@andreydjason
Created May 23, 2012 13:20
Show Gist options
  • Save andreydjason/2775207 to your computer and use it in GitHub Desktop.
Save andreydjason/2775207 to your computer and use it in GitHub Desktop.
Ruby Codings :-)
#!/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