Has Crystal got static methods?

Is it possible to do static methods in modules as in Ruby ?

module Test
    self.def test
        puts "test"
    end
end
Test::test

I get a expecting token 'EOF', not 'end' if the call is in the same file ( as shown in the exemple ) and a expecting token 'CONST', not 'test' if I place the call in a different file.

What am I doig wrong ? Is there static methods in modules in Crystal ?

Upvotes: 4

Views: 542

Answers (1)

Stephie
Stephie

Reputation: 3175

The correct syntax for class methods is def self.test, not self.def test. Class methods are called using Test.test, not Test::test.

Upvotes: 7

Related Questions