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/
module Common::Config
CONFIGS = {} of _ => _
macro config(type_decl)
{% CONFIGS[type_decl.var.id] = type_decl %}
getter {{type_decl}}
end
config some_value : String
config some_id : Int32
end
macro options_from(type, *configs)
def initialize(
{% for config in configs %}
{% config = Common::Config::CONFIGS[config.id] %}
@{{config}},
{% end %}
); end
{{debug}}
end
struct Some::Config
options_from Common::Config, some_id, some_value
end
Some::Config.new 10, "foo" # => Some::Config(@some_id=10, @some_value="foo")
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