Module: FormattedLength::ModelAdditions

Defined in:
lib/formatted_length/model_additions.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_formatted_length(field = :length) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/formatted_length/model_additions.rb', line 3

def acts_as_formatted_length(field = :length)
  define_method :formatted_length do
    FormattedLength.format_to_s(send(field))
  end
  define_method :formatted_length= do |value|
    send("#{field}=".to_sym, FormattedLength.format_to_i(value))
  end
end