Blocks, classes, and end
Classes, mixins, blocks and end-delimited bodies, with an expressive
object model. Types are optional annotations layered on top, checked when you
write them.
class Order
include Comparable
def initialize(total: Int)
@total = total
end
def <=>(other: Order) = @total <=> other.total()
def total() = @total
end
orders = [Order.new(30), Order.new(10), Order.new(20)]
orders.sort().map() do |order|
order.total()
end
# => [10, 20, 30]