How To Pass References To Methods
Print Hello World
Write Basic Syntax
Use Properties
Make An If Else Ladder
Make A Branch Statement
Declare Inits
Use Lists
Use Arrays
Make A Class Hierarchy
Use Nil And Nilable Types
Use Dynamic Typing
Declare Variable Number Of Args
Read And Write Files
Check Inheritance And Implementation
Customize Object Equality
Pass References To Methods
Translate Pseudo Code To Cobra 1
Translate Pseudo Code To Cobra 2
Implement IEnumerable 1
Implement IEnumerable 2
Iterate Through Recursive Data With Yield
Make A Collection Class
Declare Contracts
Win Forms
Access MySQL
Open TK
You can refer to a method, rather than invoking it,
by using the "ref" keyword before it.

Invoking a method is far more popular than referencing/passing a method. So
invocation is the syntactically clean case (obj.toString.trim) and method
reference the verbose case (ref obj.someMethod). Also, the use of "ref"
immediately clues you in to what's going on as you read code left-to-right.

See the lines below marked with:   # <---

class Customer

    cue init(name as String, totalSpent as decimal)
        _name = name
        _totalSpent = totalSpent

    get name from var as String

    get totalSpent from var as decimal

    def toString as String is override
        # example: Snake Charmers LLC: $5,000.00
        return '[.name]: [.totalSpent:C]'

class Example

    def main

        customers = [
            Customer('Yin Yang Inc.', 10_000.00),
            Customer('Acme Inc.', 100_000.00),
            Customer('Snake Charmers LLC', 5_000.00),

        print 'Ordered by name:'
        customers.sort(ref .orderByName)  # <---
        for cust in customers, print cust

        print 'Ordered by total spent:'
        customers.sort(ref .orderByTotalSpent)  # <---
        for cust in customers, print cust

        # you can localize the comparison code with a closure
        customers.sort(do(a as Customer, b as Customer))
        # or a lambda expression
        customers.sort(do(a as Customer, b as Customer)

    def orderByName(a as Customer, b as Customer) as int is shared

    def orderByTotalSpent(a as Customer, b as Customer) as int is shared
        return a.totalSpent.compareTo(b.totalSpent)