How would you write this C# code succinctly in Ruby?

Posted by Valentin Vasilyev on Stack Overflow See other posts from Stack Overflow or by Valentin Vasilyev
Published on 2010-04-21T07:32:05Z Indexed on 2010/04/21 7:53 UTC
Read the original article Hit count: 244

Filed under:
|
|
|

Here is the code:

using System;
using System.Collections.Generic;
using System.Linq;


namespace cs2 {
    class Program {
        static void Main(string[] args) {          
          var i=Fibs().TakeWhile(x=>x < 1000).Where(x=>x % 2==0).Sum();
        }

        static IEnumerable<long> Fibs() {
            long a = 0, b = 1;
            while (true) {
                yield return b;
                b += a;
                a = b - a;
            }
        }
    }
}

If it is possible, please give an example.

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ