Taken from O'Reilly's Perl Cookbook 6.23. Regular Expression Grabbag.
CREDIT: Robert Fey
# File lib/facets/core-uncommon/facets/string/acronym.rb, line 4 def acronymize gsub(/(([a-zA-Z0-9])([a-zA-Z0-9])*)./,"\\2") end
Common Unix cryptography method. This adds a default salt to the built-in crypt method.
NOTE: This is not (presently) a common core extension and is not loaded automatically when using require 'facets'.
# File lib/facets/core-uncommon/facets/string/crypt.rb, line 11 def crypt(salt=nil) salt ||= ( (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr + (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr ) _crypt(salt) end
Considers string a Roman numeral numeral, and converts it to the corresponding integer.
NOTE: This is not (presently) a common core extension and is not loaded automatically when using require 'facets'.
# File lib/facets/core-uncommon/facets/integer/roman.rb, line 54 def roman roman = upcase raise unless roman? last = roman[-1,1] roman.reverse.split('').inject(0) do |result, c| if ROMAN_VALUES[c] < ROMAN_VALUES[last] result -= ROMAN_VALUES[c] else last = c result += ROMAN_VALUES[c] end end end
Generated with the Darkfish Rdoc Generator 2.