def now returns method name. So you can write
private def foo
p "foo is private"
end
but I had error with more difficult method:
2.1.1p2 :036 > private def refresh_prices
2.1.1p2 :037?> orders = order_items.includes(:book)
2.1.1p2 :038?> sum = 0
2.1.1p2 :039?> orders.each do |t|
2.1.1p2 :040 > t.price = t.book.price
2.1.1p2 :041?> sum += t.price * t.quantity
2.1.1p2 :042?> t.save
2.1.1p2 :043?> end
2.1.1p2 :044?> self.total_price = sum
2.1.1p2 :045?> save
2.1.1p2 :046?> end
SyntaxError: (irb):39: syntax error, unexpected keyword_do_block, expecting keyword_end
orders.each do |t|
^
without private this def returns :refresh_prices. Can anyone explain why it fails and is it a bad way to use private def?