Prefer Ruby syntax? See Red, and your Ruby will convert to JS
Written by on August 13th, 2008 in Uncategorized.
I am a fan of Ruby, and when I saw Red the framework that allows you to write Ruby and get JavaScript out the other end I was excited. It allows you to write this:
-
class MyClass
@@my_var = 500
def initialize(arg)
@arg = arg
end
def my_method
alert(@arg)
end
end
And you end up with:
-
-
1| var MyClass = function(arg) { this.arg = arg;this.myMethod = function() { alert(this.arg); } }; MyClass.myVar = 500
-
You can also have fun with blocks:
-
[1,2,3].sort do |x,y|
return y - x
end
-
-
[1, 2, 3].sort(function(x,y) { return y - x; })
-
You also get convention conversion, which can lead to some weird things such as:
-
Yahoo[:util]::Dom
-
-
Yahoo.util.Dom
-
On one hand I am excited about being able to think that I am hacking on Ruby, even though I am not. On the other hand, I worry about the abstraction leaking (ending with weird bugs) and how ruby is great because of all of the MOP, the libraries, and other things that you can’t really do with this system. This makes it a bit of a tease.
Source: Ajaxian » Front Page
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/363812875/prefer-ruby-syntax-see-red-and-your-ruby-will-convert-to-js