Fix 'undefined method `gsub' for nil:NilClass' when undefined method is called.

Closes #1388.
http://stackoverflow.com/questions/18037596/error-undefined-method-gsub-for-nilnilclass/18038912