私のDBからすべてのコメントを収集し、ハッシュに挿入するスクリプトを作成しています。私は、コメントのハッシュに収集し、二つの別々のコメントハッシュ(vid_comments & wall_comments)Ruby:配列を使って作業する
w_hash["comments"] << contender.profile.comments.where("created_at > DATE_SUB(NOW(), INTERVAL 1 DAY)")
w_hash["comments"].delete_if { |x| x.blank? }
w_hash["vid_comments"], w_hash["wall_comments"] = [], []
w_hash["comments"].each do |c|
if !c.media_id.nil?
w_hash["vid_comments"] << c
elsif c.parent_id == 0
w_hash["wall_comments"] << c
end
end
はコードを短くするためにとにかくありにコメントを分割するのですか?私はRuby(PHPのインポート)にはかなり新しいので、私が間違っているかもしれない事について私の無知を言い訳します。
EDIT:@Mchl(下記)からのコードビットに追加されました..私は見
質問をhttp://codereview.stackexchange.comに移動することを検討してください。 – maerics
ありがとう!ポストはcodereviewに移動しました:http://codereview.stackexchange.com/questions/3987/ruby-working-with-arrays – dennismonsewicz