Feature/ruby support update#18
Open
NoorFatima-code wants to merge 3 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ruby Support — Major Update
What it was before
Originally, the applyRubyDialect() function was very basic. It only handled:
puts and print (Ruby's print commands)
if / elsif / else / unless / while / until
def (function definitions) — but only with simple names
end (closing a block)
nil (Ruby's "empty value")
Everything else in Ruby — method names with ?/!, different loop styles, classes, error handling — wasn't supported at all. Because of this, more than 12 out of the Ruby test files were crashing.
What's been added now
Method names containing ? or !
Ruby commonly uses names like prime?, zero?, save!. These used to crash the transpiler. Now they're safely renamed (e.g. prime? → prime_q) so the system can understand them. Care was also taken so normal text (like "Hello, World!") doesn't get mistakenly treated as a method name.
Ruby's different loop styles
5.times do |i|
(1..100).each do |n|
array.each do |x|
array.each_with_index do |x, i|
a.upto(b) do
a.downto(b) do
loop do (infinite loop)
Any generic something do |x| ... end pattern
All of these now convert correctly.
3. case/when/else (Ruby's switch statement)
Previously not supported at all. Now it correctly converts into an if-else chain.
4. Classes
class Animal, class Dog < Animal (inheritance) — now convert into the correct format.
5. attr_reader / attr_accessor / attr_writer
For now, these are commented out (proper support planned for the future).
6. @variable (instance variables)
Previously not supported. Now converts into the correct format.
7. raise (throwing errors)
Previously not supported at all. Now converts into the correct syntax.
8. begin / rescue / end (error handling)
Our system doesn't support try/catch yet. So this is now safely skipped — the normal code still runs, only the error-handling part is skipped (turned into a comment), so it doesn't crash.
9. ClassName.new(...)
Previously not supported. Now converts into the correct constructor-call format.
10. File.exist?
Turned out the system uses a different actual name for this, so it's now matched correctly.
11. Modifier if/unless
One-line conditions like break unless swapped now convert correctly too.
12. .length / .size
Previously this sometimes incorrectly matched the whole line. Now it only matches the correct part.