Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Phil Cohen

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Ruby Array Swap Values

// USAGE:
// a = [1,34,nil,14,5,2,nil,nil,9]
// a.swap!(nil, 0)
// a.swap(0, "No Data")

class Array
  def swap(from, to)
    collect { |value| value == from ? to : value }
  end

  def swap!(from, to)
    collect! { |value| value == from ? to : value }
  end
end

OSX Restart Lookupd

sudo kill -HUP `ps -ax | grep lookupd | grep sbin | awk '/(\d+).*/ { print $1 }'`
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS