Skip to content

Instantly share code, notes, and snippets.

@lis2
Created July 3, 2014 02:06

Revisions

  1. lis2 created this gist Jul 3, 2014.
    11 changes: 11 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    {: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