ruby -c filename # for syntax check
ruby -w filename # for warnings
ruby -wc filename # for both
I’d love to learn if there’s a programmatic way to do this within Ruby,
but I haven’t found it in the source code, and I’d rather than bring in
the rubinius melbourne parser.
This is how sandi_meter does it
Open3.capture3(‘ruby -wc’, stdin_data: source)
But that’s potentially pretty buggy on non *NIX OS’s or non-mri rubies.
Does that possibly help? (Does anyone know how to do this within ruby?)
On Wed, Dec 11, 2013 at 11:08 AM, Thyago Barbosa Rodrigues [email protected] wrote:
true
rescue SyntaxError
false
end
Why insert the throw before the code to be checked? If throw comes first,
shouldn’t it always jump out of the eval before checking src?
Sorry for slowing the conversation down, just seeing an opportunity to learn
It is to ensure that you don’t execute the code just yet. You want
only to check the syntax, not execute it.
eval will parse the code, raising a SyntaxError if something is
syntactically wrong, then start executing it. First thing is the
throw, so it throws, skipping all the rest.
Actually, I want to separate out parsing(for syntax checking) and
execution.
In our Application, we are using eval, instace_eval, class_eval etc.
what i want to do is that parse code block for syntax checking at early
stage and defer the execution at later stage.
robert
Sorry for late update.
Robert,I was trying this as follows
def method method_name, &code_block
code = eval(“lambda {#{code_block}}”)
code.call
end
method :method1 do
sytem(“echo ‘this is method1’”)
end
i am getting following error:-
test1.rb:10:in method': (eval):1:in methode’: compile error
(SyntaxError)
(eval):1: syntax error, unexpected $end
lambda {#Proc:[email protected]:33}
^
from test1.rb:33:in eval' from test1.rb:10:in method’
from test1.rb:33