• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

ActiveRecordを読み込んだ状態でirbを使っているときに、TAB補完をしようとすると落ちることが結構な頻度でありました。
原因を調べてみると、補完候補のArrayをsort使用としているところで、Symbolに対して <=> 演算子を呼びだそうとしてエラーが発生しているようです。
補完候補は Object#instance_methods から得ているようなので、なぜSymbolが要素として混入するのかが謎だったのですが、どうやら
Arel::Attribute::Predications クラスが犯人のようです。

ruby>>
PREDICATES = [
:eq, :eq_any, :eq_all, :not_eq, :not_eq_any, :not_eq_all, :lt, :lt_any,
:lt_all, :lteq, :lteq_any, :lteq_all, :gt, :gt_any, :gt_all, :gteq,
:gteq_any, :gteq_all, :matches, :matches_any, :matches_all, :not_matches,
:not_matches_any, :not_matches_all, :in, :in_any, :in_all, :not_in,
:not_in_any, :not_in_all
]

Predications = Class.new do
def self.instance_methods *args
warn "this module is deprecated, please use the PREDICATES constant"
PREDICATES
end
end
<<--

このコードを書いた人は instance_methodsはStringの配列を返すという事を失念していたようですね。
irb/completeはObjectSpaceから補完候補を拾ってくるので、上述のコードがあるせいでSymbolが補完候補配列に混入してしまいます。

回避策としては、irb起動時に以下のようなコードを読み込むなどがあります。

ruby>>
module Arel
class Attribute
class Predications
def self.instance_methods
require 'arel/algebra/attributes/attribute'
Arel::Attribute::PREDICATES.map(&:to_s)
end
end
end
end
<<--

追記

この問題は 1.8.x系のRubyでのみ発生するようです。
thanks
@a_matsuda!

posted by genki genki on Thu 7 Jul 2011 at 12:31 with 0 comments
Contents rssrss
光ファイバーを二次元振動させて走査するAR用ディスプレイ
因果の取り違え
Swift2's defer for CoffeeScript
mongodb-3.0からcreateIndexのdropDupsが無くなったらしい
mongodb-3.0以降のWiredTigerの設定を動的に変更する方法
一般楕円の高速生成アルゴリズムへの道標
farro mantecatoのレシピ
Droonga関連の記事のまとめ
RuntimeErrorの特定のメッセージに限定してrescueする方法
jQueryでscriptタグを実行せずにappendする
Tags
coffeescriptdefergroongajsmemonodenodejs
Comments rssrss
http://ldm.sakura.ne.jp/balu+bbbs/album/album.cgi?mode=detail&no=210 http://ldm.sakura.ne.jp/balu+bbbs/album/album.cgi?mode=detail&no=210: Aw, this was an incredibly good post. Taking the t... 04/25 18:19
https://www.bigbeargum.com/2019/02/15/ambrose-redmoon/ https://www.bigbeargum.com/2019/02/15/ambrose-redmoon/: Hello would you mind letting me know which hosting... 04/25 17:39
http://zeroken.jp/1978td/album/album.cgi?mode=detail&no=20 http://zeroken.jp/1978td/album/album.cgi?mode=detail&no=20: Asking questions are genuinely fastidious thing if... 04/25 17:26
https://natucci-estetica.com/?attachment_id=1376 https://natucci-estetica.com/?attachment_id=1376: Hello there, You have done a fantastic job. I wi... 04/25 17:05
https://www.waimaoz.com/23019.html?unapproved=5151&moderation-hash=a14b2a811444fc3059edb7c1441d076e https://www.waimaoz.com/23019.html?unapproved=5151&moderation-hash=a14b2a811444fc3059edb7c1441d076e: Good day! Do you use Twitter? I'd like to follow y... 04/25 16:50
https://bysystem.ru/process-proizvodstva-kartonnyh-korobok-i/ https://bysystem.ru/process-proizvodstva-kartonnyh-korobok-i/: Требовалось производство картонных коробок в сжа... 04/25 15:33
https://marialionsa.ru/proizvodstvo-kartonnyh-korobok-i-upakovki/ https://marialionsa.ru/proizvodstvo-kartonnyh-korobok-i-upakovki/: Документооборот четкий, все закрывающие акты предо... 04/25 15:05
https://example.com/oqaphq https://example.com/oqaphq: This post is genuinely a pleasant one it assists n... 04/25 12:43