Sha256: 9788caeafe989119d26947a5f909ad52c2443b69ccfa44dc8d49a68d50231147
Contents?: true
Size: 925 Bytes
Versions: 1
Compression:
Stored size: 925 Bytes
Contents
# encoding: utf-8 String.class_eval do # Genderifies string. This is done by replacing every occurence of (x|y) # with either left (x) or right part (y) of it based on the gender provided as argument. # If argument of function is :f, 'f', :F, 'F', 1, '1', :female or 'female' it will pick # the right side. Anything else, including nil, will use the left side as replacement. # Hm, is this sexist? # # Argument can also be an object that responds to 'gender' call. Returning value of such # function will be applied to stated rules above. # # Example: # # >> "About (him|her)".genderify(:f) # => "About her" # def genderify(genderable) gender = genderable.respond_to?(:gender) ? genderable.gender : genderable gsub(/\((.+?)\|(.+?)\)/) do case gender when :f, 'f', :F, 'F', 1, '1', :female, 'female' $2 else $1 end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
genderify-0.0.2 | lib/genderify/string_ext.rb |