I’m executing some tests on crystal interactive with one module and struct and have error calling one class method as below:
crystal i
Crystal interpreter 1.16.3 (2025-05-12).
EXPERIMENTAL SOFTWARE: if you find a bug, please consider opening an issue in
https://github.com/crystal-lang/crystal/issues/new/
icr:1> module Space
icr:2> struct Age
icr:3> ORBITALS = {
icr:4> "Mercury" => 0.2408467,
icr:5> "Venus" => 0.61519726,
icr:6> "Earth" => 1.0,
icr:7> "Mars" => 1.8808158,
icr:8> "Jupiter" => 11.862615,
icr:9> "Saturn" => 29.447498,
icr:10> "Uranus" => 84.016846,
icr:11> "Neptune" => 164.79132,
icr:12> }
icr:13>
icr:14> EARTH_YEAR = 31_557_600
icr:15> @@age : Int64 = 0
icr:16>
icr:17> def self.from_seconds(sec : Int64)
icr:18> @@age = sec
icr:19> end
icr:20>
icr:21> def self.age_on_earth
icr:22> (@@age/EARTH_YEAR).round(2)
icr:23> end
icr:24>
icr:25> def self.age_on_mercury
icr:26> (@@age/EARTH_YEAR/ORBITALS["Mercury"]).round(2)
icr:27> end
icr:28>
icr:29> def self.age_on_venus
icr:30> (@@age/EARTH_YEAR/ORBITALS["Venus"]).round(2)
icr:31> end
icr:32>
icr:33> def self.age_on_mars
icr:34> (@@age/EARTH_YEAR/ORBITALS["Mars"]).round(2)
icr:35> end
icr:36>
icr:37> def self.age_on_jupiter
icr:38> (@@age/EARTH_YEAR/ORBITALS["Jupiter"]).round(2)
icr:39> end
icr:40>
icr:41> def self.age_on_saturn
icr:42> (@@age/EARTH_YEAR/ORBITALS["Neptune"]).round(2)
icr:43> end
icr:44> end
icr:45> end
=> nil
icr:46> Space::Age.from_seconds(1000000000).age_on_earth
error in line 1
Error: undefined method 'age_on_earth' for Int64
Please I need help because don’t understand that error. To me nothing incorrect on module and class.