I’m getting “undefined method” for a method I’ve defined, in line 5 of main.cr, where foo() is being called. I’ve looked at real Crystal programs written by people who know what they’re doing, re-read the language reference GitBook, and googled. I’m missing some syntax detail with my swiss-cheese C++ rotted brain!
In file alpha.cr:
In file main.cr, the main program:
z = foo(10) <=== Error: undefined method
def self.foo(...) (add
self. to make it a module method)
Ah! It works!! IT’S ALIVE!!!
Problem solved. Thank you!
The odd little details I read about but don’t absorb…
It’s as if ‘module’ were ‘class’ in a way. What my python-addled creaky old rust-trap brain thinks is a global function (or variable or some other thing) is really a member of a “class” that’s called a module, and I sortof have to pretend I’m doing Python where you put “self.” in certain places (lots of places in actual Python.)
If you feel more comfortable, there’s a common Ruby pattern usable in Crystal:
x * x
puts MyClass.foo 2
extend will use the instance method of
ClassMethods module in