- Spend some time moving your way through the 46 Ruby coding examples in the Ruby Tutorial with Code from http://www.fincher.org/tips/Languages/Ruby/
- What are the syntax differences in the way that Ruby and Javascript use the if statement?
- While Ruby and Python are quite similar, can you find some similarities between Ruby and Javascript?
Yah, the tutorial exists. I have worked my way through the 46 examples.
I particularly like multiple return values, open classes and what you can do with arrays. Ruby is a pretty flexible language.
2)
The if statment for Ruby is as follows. Note the ruby uses elsif (without the e):
if condition1
code to be executed if condition1 is true
elsif condition2
code to be executed if condition2 is true
else
code to be executed if condition1 and condition2 are not true
end
The JavaScript version is as follows:
if (condition1)
{
code to be executed if condition1 is true
}
else if (condition2)
{
code to be executed if condition2 is true
}
else
{
code to be executed if condition1 and condition2 are not true
}
3)
The main similarities between Ruby and JavaScript are as follows:
- They are both dynamically typed
- They are both object oriented
- They both have classes
- They both have functions that return values. For procedures or subs that don't return a value the function keyword is still used.
- JavaScript uses the keyword this and Ruby uses self
References
JavaScript Eye for the Ruby Guy (n.d.). Retrieved June 22, 2009, from http://tore.darell.no/pages/javascript_eye_for_the_ruby_guy
No comments:
Post a Comment