これが最初の私のコードです
def participation_earning(partcpnt_usr)
case show_participant_users
when Array
puts "***********Inside Array Statement - #{Time.now} *********"
sleep 1
show_participant_users.find do |show_prtcpnt_usr|
show_prtcpnt_usr.show_participant_id == partcpnt_usr.participant_id
end
when ActiveRecord::Relation
puts "***********Inside Relation Statement - #{Time.now} *********"
sleep 1
show_participant_users.where(:show_participant_id => partcpnt_usr.participant_id).first
else
puts "Will always go in else part"
end
end
いくつかの説明show_participant_users
は、ユーザーの関係オブジェクトのようなものです
@user.show_participant_users
今私を悩ませているのは、クラスshow_participant_users
が配列であるにもかかわらず、それがまだelseブロックに入り、理由がわからないことです(配列でshow_participant_users
はないnil
ことを確認するためだけに)
逆に、以下のコードは期待どおりに機能します
array_fields = []
case array_fields
when Array
puts "Ruby Array"
when Hash
puts "Ruby Hash"
end
簡潔さのために使用したくない if/else ステートメント以外のアイデア
ありがとうございます