Skip to content

Instantly share code, notes, and snippets.

@D3MZ
Created September 7, 2012 20:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save D3MZ/3669259 to your computer and use it in GitHub Desktop.
Save D3MZ/3669259 to your computer and use it in GitHub Desktop.
dn work
class String
def split_to_array
encoding_options = {
:invalid => :replace, # Replace invalid byte sequences
:undef => :replace, # Replace anything not defined in ASCII
:replace => ' ', # Use a blank for those replacements
:universal_newline => true # Always break lines with \n
}
string = self.encode(Encoding.find('ASCII'), encoding_options)
string = string.split("\n").delete_if {|x| x.empty?}
string.length > 2 ? string : string.split(". ")
end
end
s = "Directions:\n\nPlace all ingredients together in a microwave safe dish.  Cover and cook for 5 minutes or until apples are tender.  Stir and serve!\n\n\n"
s.split_to_array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment