I have Kotlin, C#, C++, and Rust if I need static typing. Ruby is for when I don't.
I occasionally wonder whether it might be possible to accommodate more dynamic language features with a compiler that treats them like a macro system that is expanded statically, such that no actual dynamicism is necessary at runtime.
Plus it is faster than Go/Java/Elixir. As others have pointed out, Crystal does have meta programming capabilities.
[:thing, :other_thing].each do |msg|
define_method(msg) do
@json[msg].to_s
end
end
When this is far more clear and, for me, aesthetically pleasing: def thing
@json[:thing].to_s
end
def other_thing
@json[:other_thing].to_s
end
I'm not sure how you'd use a ruby object that maps to an OpenAPI spec if you don't know what's in the API response until runtime... surely you or the user of your library has an idea what's in the API they are consuming?I full-stop don't do codegen in any project under any circumstance that is not done strictly within the workflow of a build tool (i.e., a Maven generated-sources gizmo). OpenAPI's options are pretty much all exactly not that: all the codegen options's happy paths seem to be vendoring generated code. And that makes me itch, too.
You can build your code at runtime from the spec and then compile it at runtime to get pretty good performance.
I'm also not sure Crystal can implement an active record pattern off of a database? (Though I am not personally the type to go with that, I prefer row mappers.)
https://github.com/amberframework/granite-orm https://github.com/sam0x17/crystal-mongo-orm
At that point, you may (should) just use an object mapper like ROM that has no model-class hooks at all. (Which I actually like. But the Rails world disagrees.)
You're trying to slice too fine. Crystal can't do this. That's OK. Own it, don't try to hide it.
However, that is basically a lookup table using string based dispatch to decide what to execute, and such a lookup table can be done in anything.
For me, everything that Ruby is valuable for is retained. I'm able to do all the things I did in Ruby just fine, and it prevents me from doing a lot of things I shouldn't have been doing.
We recently migrated our app from Rails to Crystal (using the Amber framework) and our code base is now 2/3rds the size and we eliminated hundreds of bugs in the process simply from static typing and explicit nil handling. Our response times are also now all under 30ms where we were at 100ms+ before.