Skip to content

Instantly share code, notes, and snippets.

@lis2
Created July 3, 2014 02:10
Show Gist options
  • Save lis2/916c1ef78f1e56c2c8f4 to your computer and use it in GitHub Desktop.
Save lis2/916c1ef78f1e56c2c8f4 to your computer and use it in GitHub Desktop.
{:title => 'Anchor date:', :result => fields_to_na(try_chain(@selected_band, :anchor_on, :to_au))}
def fields_to_na(data)
return 'N/A' if data.blank?
return yield(data) if block_given?
data
end
def try_chain(object, *methods)
methods.inject(object) {|o, a| o.send(:try, a) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment