Happy birthday Ruby! It's 24th in the US now, while it is still 24th in Japan. So it is neither too early nor to late:) It is also a perfect chance(and a happy coincidence, I didn't plan to release on this day, it just happens) to show you some of my latest work. The result looks like this:
From a comparison of the two versions of source code you can see that a lot of things can be achieved purely in the Ruby side:
- While you can use
console.log. This is because Ruby does not distinguish between
- For new call, instead of
new bar(), we need to use
bar.invoke_new, since I haven't found a good way to implement
newfunction. Maybe I need to check rspec for inspiration-_-
- You can create a variable that caches a function: such as:
However, to invoke this function, you need to use following syntax:
This is now only a temporarily solution, I may find a way to work around this.
- Suppose you want to call a
setfunction on an object
foo, you cannot directly do a
setis already used in Ruby side, what you can do here is one of the following solutions:
- When adding Ruby Procs as callback functions, you can either directly create a proc:
You can also use existing functions as callbacks, but do remember you need to use the following syntax:
While we still use a symbol to represent a function,
to_proc must be invoked to tell webruby that we want to use the actual function, not the
- Do remember that in current implementation of webruby, you only have the precision of float, not double. So the range that can be expressed in a number is a little limited. I will check later if we can work this around.
And there's one more TODO task: currently you cannot pass arguments to a callback function using a Ruby proc. For example, if you add arguments to
window.setInterval, they are not passed back to your Ruby Proc. I will work on this in the next few days(but not today, I have some stupid homework to finish today-_-).