Skip to content

Instantly share code, notes, and snippets.

@francirp
Last active August 8, 2016 16:23
Show Gist options
  • Save francirp/c76aa661dc88247121465a5429ddcc3d to your computer and use it in GitHub Desktop.
Save francirp/c76aa661dc88247121465a5429ddcc3d to your computer and use it in GitHub Desktop.
Decorators Codeblock 15
class BaseDecorator < Draper::Decorator
  delegate_all

  def self.currency(*keys)
    keys.each do |key|
      define_method(key) do
        h.number_with_precision(object.send(key), precision: 2)
      end

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