Skip to content

Instantly share code, notes, and snippets.

@jordelver
Forked from ahoward/a.rb
Created May 10, 2012 07:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jordelver/2651656 to your computer and use it in GitHub Desktop.
Save jordelver/2651656 to your computer and use it in GitHub Desktop.
style is the only thing.
# shitty
attributes[:name] = options[:name] unless options[:name].blank?
attributes[:first_name] = options[:first_name] unless options[:first_name].blank?
attributes[:last_name] = options[:last_name] unless options[:last_name].blank?
attributes[:linkedin_id] = options[:linkedin_id] unless options[:linkedin_id].blank?
attributes[:company] = options[:company] unless options[:company].blank?
attributes[:company_id] = options[:company_id] unless options[:company_id].blank?
attributes[:linkedin_picture_url] = options[:linkedin_picture_url] unless options[:linkedin_picture_url].blank?
# shitty, but i can read it...
attributes[:name] = options[:name] unless options[:name].blank?
attributes[:first_name] = options[:first_name] unless options[:first_name].blank?
attributes[:last_name] = options[:last_name] unless options[:last_name].blank?
attributes[:linkedin_id] = options[:linkedin_id] unless options[:linkedin_id].blank?
attributes[:company] = options[:company] unless options[:company].blank?
attributes[:company_id] = options[:company_id] unless options[:company_id].blank?
attributes[:linkedin_picture_url] = options[:linkedin_picture_url] unless options[:linkedin_picture_url].blank?
# at least it's DRY, but fuck it's hard to read...
[:name, :first_name, :last_name, :linkedin_id, :company, :company_id, :linkedin_picture_url].each do |key|
attributes[key] = options[key] unless options[key].blank?
end
# minimum required to be good
#
# * the variable name makes the intention clear
# * the list isn't jammed onto one line hiding typos and confounding quick editing
# * it's primed for configuration (whitelist is an option)
# * stack errors come from *one line*
# * it separates the logic of listing what to whitelist and how to extract a key from options
# * reading a commit diff is actually possible (thanks @drbrain)
#
whitelist = [
:name,
:first_name,
:last_name,
:linkedin_id,
:company,
:company_id,
:linkedin_picture_url
]
whitelist.each do |key|
attributes[key] = options[key] unless options[key].blank?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment