The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
Process.fork
. https://gist.github.com/postmodern/a98e68dff96163b5f234cd9de1c5c75d
self.foo
at the module level in one file, and in another file I have a struct defined in the same module. I would like some of the instance methods of the struct to be able to use the private foo method at the module level, but I cannot fully qualify it, and it is not part of the struct so I'm not sure if this is possible. I'm trying to write a file of private helper methods that are used in several other files/structs
crystal doc
.
Process.fork
does exist but is nodoc'ed / part of the private API. https://github.com/crystal-lang/crystal/blob/1.0.0/src/process.cr#L62-L98
Mine probably doesn't do exactly what I expect.
Also, stupid question: I've never seen the double colon syntax for module name as in your example...where is this documented?
!
suffix.
module Origin
private DEFAULT_TOLERANCE = 1e-7
def self.=~(x : Float64, y : Float64, rel_tol : Float64 = DEFAULT_TOLERANCE, abs_tol : Float64 = rel_tol)
(x - y).abs <= Math.max(abs_tol, rel_tol * Math.max(x.abs, y.abs))
end
end
Interestingly, this can be called as a fully-qualified method: Origin.=~(a, b, rel_tol: c, abs_tol: d)
, or a binary operator without qualification if the defaults are sufficient: a =~ b
. I'm not sure why the former requires qualification.