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.

def mask_number(number)
  number.to_s.size < 5 ? number.to_s : (('*' * number.to_s[0..-5].length) + number.to_s[-4..-1])
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.

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