LoginSignup
0
0

More than 5 years have passed since last update.

StructでObjectをソートするのが便利

Posted at

executed_dateとaction_dateで以下のObjectをソートしたいです。

system_log = SystemLog.create type: "clean", executed_date: Time.today
user_log= UserLog.create action_type: "create user", action_date: Time.today.yesterday,:info: "info"

Structでソートしたら簡単になると思います。

Log = Struct.new :log, :date
logs = Array(Log.new(system_log, system_log.executed_date), Log.new(user_log, user_log.action_date)
logs.sort_by(:&date)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0