Skip to content

Instantly share code, notes, and snippets.

@francirp
Created August 8, 2016 16:25
Show Gist options
  • Save francirp/7ed8218e12fa4d09c4dd1e68e469ab75 to your computer and use it in GitHub Desktop.
Save francirp/7ed8218e12fa4d09c4dd1e68e469ab75 to your computer and use it in GitHub Desktop.
Decorators Codeblock 17
def self.percent(*keys)
  keys.each do |key|    
    define_method(key) do
      h.number_with_precision(object.send(key) * 100.0, precision: 1)
    end

    define_method("display_#{key}") do
      h.number_to_percentage(object.send(column_name) * 100.0, precision: 1)
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment