Skip to content

Instantly share code, notes, and snippets.

@joshuapinter
Created November 14, 2013 03:54
Show Gist options
  • Save joshuapinter/7461083 to your computer and use it in GitHub Desktop.
Save joshuapinter/7461083 to your computer and use it in GitHub Desktop.
Simple String method to only symbolize with a given array of whitelist values.
class String
def symbolize_with_care *args
valid_values = args
valid_values.each do |v|
if v.to_s == self
return v
break
end
end
raise "No valid values to symbolize #{self}."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment