1

How can I check if Ruby code is parsable, without executing it?

Basically, I want the functionality of ruby -c code.rb, without actually writing to a temporary file. Note that there is the problem of properly escaping the code if one is to use ruby -ce 'some_ruby_code'.

Ideally, there should be something in the standard lib, but I couldn't find it.

1
  • @Felix awesome, I will close this question as duplicate when I go home. Not sure how I missed that. Thanks a lot! Commented Sep 13, 2016 at 15:53

1 Answer 1

1

ruby -c can read from standard input, like in cat code.rb | ruby -c.

Interactively you can ruby -c, type in text and press Ctrl+D to signalize end-of-file.

Examples are for Linux/Unix, no idea how this would work in Windows.

Sign up to request clarification or add additional context in comments.

2 Comments

That is a possible workaround. However, I would prefer if I could stay in ruby. Piping is better than reading/writing files, but still has its issues. Ideally, I don't want to call external commands at all.
I think your question is a duplicate, then :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.