lunes, 19 de septiembre de 2011

Fastruby 0.0.8 released with support for lambdas

Fastruby is a gem which allows to execute ruby code much faster than normal, currently in a state of transition between a spike and a usable gem, it is released when possible with incremental improvements.
The version v0.0.8 was released with the new feature of supporting lambdas. Functional improvement does not appear to be important, but the underlying internal implementation will allow new features in the next release such as the support for proc and continuation objects.

Install

You can clone the repository at github:
git clone git://github.com/tario/fastruby.git
Or install it using gem install:
gem install fastruby
New Features
Examples of code being supported

Scope retention (lambda has a reference to the scope where it was created)

  1. require "fastruby"  
  2.   
  3. fastruby '  
  4. class X  
  5.   attr_accessor :lambda_set:lambda_get  
  6.   def initialize  
  7.     a = nil  
  8.   
  9.     @lambda_set = lambda{|x| a = x}  
  10.     @lambda_get = lambda{a}  
  11.   end  
  12. end  
  13. '  
  14.   
  15. x = X.new  
  16.   
  17. x.lambda_set.call(88)  
  18. p x.lambda_get.call  

Yield block of the scope

  1. require "fastruby"  
  2.   
  3. fastruby '  
  4. class X  
  5.   def bar  
  6.     lambda_obj = lambda{  
  7.       yield  
  8.     }  
  9.     lambda_obj  
  10.   end  
  11.   
  12.   def foo  
  13.     a = 77  
  14.     bar do  
  15.       a  
  16.     end  
  17.   end  
  18. end  
  19. '  
  20.   
  21. x = X.new  
  22.   
  23. lambda_obj = x.foo  
  24. p lambda_obj.call  # 77  


No hay comentarios:

Publicar un comentario