ActiveSupportについてるObject#in?メソッド
Object#include?の逆をやってくれる便利なメソッドなんだが, Railsを4にあげて実行するとエラーになるから書き換えなきゃいけない
※Rails4.2に付随するActiveSupportでチェックしている、Rails4.0ではチェックしていない
# includeの例
[1, 2, 3].include?(2) => true
# Rails3.2まではこちら通る
2.in?(1, 2, 3) => true
# Rails4以降はこちら, Rails3.2でもこのコードで通る
2.in?([1, 2, 3]) => true
in?の使用箇所のソースコード
active supportのin?メソッドの引数が、*を使った引数の数を指定しない形から, 配列に変更になった
変更前
def in?(*args)
if args.length > 1
args.include? self
else
another_object = args.first
if another_object.respond_to? :include?
another_object.include? self
else
raise ArgumentError.new("The single parameter passed to #in? must respond to #include?")
end
end
end
変更後
def in?(another_object)
another_object.include?(self)
rescue NoMethodError
raise ArgumentError.new("The parameter passed to #in? must respond to #include?")
end