Following the release of version v0.0.8 which did implement several internal improvements including a new non-linear stack structure, the new release v0.0.9 implements the support for procedure objects based in the previous implementation
Install
You can clone the repository at github:
git clone git://github.com/tario/fastruby.gitOr install it using gem install:
git checkout v0.0.9
gem install fastruby
New Features
Examples of code being supported
return method from proc
require "fastruby"
fastruby '
class X
def foo
pr = Proc.new do
return "return foo from inside proc"
end
pr.call
return "return foo"
end
end
'
x = X.new
x.foo # this returns "return foo from inside proc"
The behavior of Proc objects (those created using Proc.new) are very similar to the behavior of lambdas, but with a few little differences:
- It is possible to do non-local return's from Proc.new of the method where the block was defined, this non-local return will fail with LocalJumpError when the method scope is closed in the moment of invoking the return (in lambdas, return only acts as next; ie, only ends the lambda function)
- Break jumps are illegal from Proc.new blocks and always fails with LocalJumpError (in lambdas, break acts as next)
As additional note, block objects created using proc method are exact the same block objects created using lambda method, only check the the ruby 1.8 source code to see something like that:
...
rb_define_global_function("proc", proc_lambda, 0);
rb_define_global_function("lambda", proc_lambda, 0);
...
No hay comentarios:
Publicar un comentario