returning は死んだ。 Object#tap を使おう

標記のとおり、死ぬみたいです。

crankharder

I’m curious to know what the rational is behind this?

rohit

You can now use tap.

正論過ぎて返す言葉もありませんね。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
require "rubygems"
require "active_support"
 
a1 = returning [] do |ary|
  ary << 'hoge'
  ary << 'fuga'
end
 
a2 = [].tap do |ary|
  ary << 'hoge'
  ary << 'fuga'
end
 
require "spec"
a1.should == a2
#=> true

確かに、タイピング量的にも、tapの方が少なくなりますね。でも、1.8.6みたいにtapのバックポートが無い場合とか、あとreturningを使いまくってる場合は…。

そもそもtapもreturningも4行ぐらいで実装できるので、以下のような config/initializers/returning_strikes_back.rb を作成すれば互換性を確保できるんじゃあないでしょうか。あまり薦めませんが。。

1
2
3
4
5
6
7
8
9
10
module ReturningStrikesBack
  def returning(value)
    yield(value)
    value
  end
end
 
class Object
  include ReturningStrikesBack
end

UA – 『KABA』

特に深く考えずに手にしたんだけど、すごくいいね! どこかで聞いたことのある唄のカバー集。

KABA / Array

ビクターエンタテインメント( 2010-06-23 )


「きっと言える」が良かったです。

* * *

UAで一番好きな唄。

Ubuntuでkumofsのdebを作成する

kumofsは、memcache互換のプロトコルをサポートする分散型KVS。

なぜかまだだれもdebを公開していなかったようなので、作り方を調べてみました。

Read the rest of this entry »