I hereby claim:
- I am bcardiff on github.
- I am bcardiff (https://keybase.io/bcardiff) on keybase.
- I have a public key whose fingerprint is A2BC 755E D6EE AC60 6C7E D13D 2BFD 635A 00D0 2045
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
This intent to show how Ruby practice can be addapted to Crystal. With a total different under the hood implementation, but keeping some of the greatest aspects.
The focus thou is not to stand on how a fsm should be modeled, or defined by a dsl, BUT how some common Ruby practices might be rethinked to take advantage of Crystal.
As an intermediate step, I sometimes like to think in a more plain type/classes design to have a nice compile time experience, but using macros in crystal to reach that from a nice dsl.
NB: There is consideration to name the examples a language way and not the language way .
require "compiler/crystal/**" | |
class Object | |
def dump_inspect(io, level) | |
io << " " * level | |
to_s(io) | |
io << " :: " << self.class | |
end | |
end |
macro for(expr) | |
{{raise "invalid syntax. use for e in c." unless expr.args.first.name.stringify == "in"}} | |
{{expr.args.first.args.first}}.each do |{{expr.name.id}}| | |
{{expr.args.first.block.body}} | |
end | |
end | |
for e in 1..5 do | |
puts e | |
end |
.crystal |
Compiling
crystal build main.cr
will change Settings
declaration in main.cr
from
class Settings
Experiment for wkhtmltopdf
brew install wkhtmltopdf
crystal wkhtmltopdf.cr
known issue: althout conversion succeeds the wkhtmltopdf process seems to hanging in the very end :-(
require 'date' | |
target = ARGV[1] || "." | |
files = %x(git grep -n 'TODO*' #{target}) | |
lines = [] | |
length_author = 0 | |
length_file = 0 |
macro collect_alias_method(method, type) | |
def {{method}} | |
res = [] of {{type}} | |
{{method}} do |e| | |
res << e | |
end | |
res | |
end | |
end |