I'm making a DSL in crystal, and I'm trying to get a syntax like ~{do_something}
I tried something like this:
def ~(&block)
block.call
end
def my_func
puts "hello"
end
~ { my_func }
But all I get is this error:
Error in line 11: undefined method '~' for Tuple(Nil)
I tried to replace {...}
with do; ...; end
without much success:
~ do; my_func; end
And I got:
Syntax error in eval:11: expecting token 'EOF', not 'end'
- Can you explain why to I get theses error ?
- Is there a way to make this syntax to work ?