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

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

Mask all but last 4 digits

If you need to mask all but the last 4 digits of a nubmer - like a credit card number - this helper works nicely.

Just pass it a number or string.

   1  
   2  def mask_number(number)
   3    number.to_s.size < 5 ? number.to_s : (('*' * number.to_s[0..-5].length) + number.to_s[-4..-1])
   4  end

Check for under age

This function can be used to check if a user is underage.

Note: This is using rails core extensions. It'd need to be modified a bit for a pure ruby implementation.

   1  
   2  def underage?(birthday)
   3    18.years.ago < birthday
   4  end
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS