12 Apr '13, 2pm

Rubyist Magazine - Ruby 2.0.0: Enumerable#lazy

The lazy version of 'map' is very convenient, but there is a issue with the method names. The Enumerable module includes many other methods that can be lazily evaluated, such as 'map', 'select', 'reject' and 'drop', but we did not want to inflate Enumerable module with methods such as 'lazy_map' and 'lazy_select'. Then I came up with an API that changes its mode by appending .lazy. I added a method called "lazy" in the Enumerable module. If you call this method, it returns an instance of a special class called Enumerator::Lazy. Enumerator::Lazy is almost identical to Enumerator, but certain methods (such as 'map' and 'select') are overwritten by the lazy version. Now you can rewrite the previous example like this in Ruby 2.0. File.open(path) do |f| puts f.each_line.lazy.map{|line| ...(modify line)...} .select{|line| ...(return true if line matches the condition)...} .first...

Full article: http://jp.rubyist.net/magazine/?Ruby200SpecialEn-lazy

Tweets

@nari3 にあったけど、このページって左の SideMenu から探そうとすると「注意点」...

jp.rubyist.net 04 Apr '13, 5am

Magic Comment を書いていないファイルの文字列リテラルのエンコーディング (default script encoding) が UTF-8 に変更されました。[#6679] Ruby 1.9 においては、default scrip...

@vestige_ ここに Ruby とは?の記述がありました。

ruby-lang.org 13 Apr '13, 3pm

Content available in English , French , Japanese , Korean , Polish , Spanish , Portuguese , Simplified Chinese , Tradition...

Ruby Weekly issue 140 is out:

rubyweekly.com 11 Apr '13, 2pm

Working With Ruby Threads E-book Released Jesse Storimer, author of Working with Unix Processes and Working with TCP Socke...