In Scala how do you write a init function?

initialization, scala

Solution

In scala you write all init in class/trait/object body:

class Foo(price: Int) {
  val currentPrice = price
}

or simply

class Foo(val currentPrice: Int) {

}

You can think of class body as of primary constructor method, as DNA said.

Problem

For example, in Ruby I can write ``` def initialize(price) @Current_price = price end ```

Original source