Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 550
Matthieu Raynaud de Fitte Avatar asked Mar 07 '23 21:03

Matthieu Raynaud de Fitte


1 Answers

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

like image 147
Stephie Avatar answered Mar 10 '23 09:03

Stephie