refactoring question

Hi, guys. I changed some columns types to decimal in database, but the
code is not DIY. Any thoughts on refactoring the following code?

change_table :accounts do |t|
t.change :check_amount, :decimal, :precision=>6, :scale=>2, :default=>0
t.change :cash_amount, :decimal, :precision=>6, :scale=>2, :default=>0
t.change :change_amount, :decimal, :precision=>6, :scale=>2, :default=>0
.
.
.
.
t.change :total, :decimal, :precision=>6, :scale=>2, :default=>0
end

Thanks in advance.

Hi, guys. I changed some columns types to decimal in database, but the
code is not DIY. Any thoughts on refactoring the following code?

change_table :accounts do |t|
t.change :check_amount, :decimal, :precision=>6, :scale=>2, :default=>0
t.change :cash_amount, :decimal, :precision=>6, :scale=>2, :default=>0
t.change :change_amount, :decimal, :precision=>6, :scale=>2, :default=>0
.
t.change :total, :decimal, :precision=>6, :scale=>2, :default=>0
end

change_table :accounts do |t|
   [:check_amount, :cache_amount, :change_amount, ..., :total].each do

c>

     t.change :c, :decimal, :precision => 6, :scale => 2, :default => 0
   end
end

Hi, guys. I changed some columns types to decimal in database, but the
code is not DIY. Any thoughts on refactoring the following code?

change_table :accounts do |t|
t.change :check_amount, :decimal, :precision=>6, :scale=>2, :default=>0
t.change :cash_amount, :decimal, :precision=>6, :scale=>2, :default=>0
t.change :change_amount, :decimal, :precision=>6, :scale=>2, :default=>0
.
t.change :total, :decimal, :precision=>6, :scale=>2, :default=>0
end

change_table :accounts do |t|
[:check_amount, :cache_amount, :change_amount, ..., :total].each do >c>
   t.change :c, :decimal, :precision => 6, :scale => 2, :default => 0

Oops... that should be:

t.change c, .....

(no colon before the c)

Philip Hallstrom wrote: