Module: StripbyAC::String
- Included in:
- String
- Defined in:
- lib/mightystring/string_stripbyac.rb
Instance Method Summary collapse
-
#strip_byac(acceptchars) ⇒ Object
Strip by Acceptable Characters : String.stripbyac(charlist) => Copy of New String (removes any character not in list).
Instance Method Details
#strip_byac(acceptchars) ⇒ Object
Strip by Acceptable Characters : String.stripbyac(charlist) => Copy of New String (removes any character not in list)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/mightystring/string_stripbyac.rb', line 11 def strip_byac(acceptchars) if not acceptchars.nil? if acceptchars.is_a?(String) return self.split('').map!{|x| if acceptchars.split('').include?(x); x end }.join elsif acceptchars.is_a?(Array) return self.split('').map!{|x| if acceptchars.include?(x); x end }.join elsif acceptchars.respond_to?(:[]) acceptchars = acceptchars.to_a return self.split('').map!{|x| if acceptchars.include?(x); x end }.join else raise "#{puts acceptchars.class}" end else raise StandardError.new('You must include a list of acceptable characters for this string in stripbyac(acceptchars)!') end end |