I’m seeing some very strange behavior while trying to sort an array with
2 elements. Here is the code:
work_periods = day_array[wday] || []
puts "work_periods=#{work_periods.inspect}"
puts "work_periods.length=#{work_periods.length}"
begin
work_periods = work_periods.sort { |a,b| puts
“a=#{a.start_time.class.inspect} b=#{b.start_time.class.inspect}”; stat
= (a.start_time < b.start_time); puts “stat=#{stat}”; stat }
rescue Exception => e
puts “e=#{e.message}\n\t#{e.backtrace.join(”\n\t")}"
raise
end
puts “got here”
And here is the output:
work_periods=[#<WorkPeriod id: 6, weekly_schedule_id: 2, site_id: 1,
day: 1, start_time: “2000-01-01 08:00:00”, end_time: “2000-01-01
12:00:00”>, #<WorkPeriod id: 476, weekly_schedule_id: 2, site_id: 2,
day: 1, start_time: “2000-01-01 14:00:00”, end_time: “2000-01-01
17:00:00”>]
work_periods.length=2
a=Time b=Time
stat=false
e=undefined method >' for false:FalseClass org/jruby/RubyArray.java:3252:in
sort!’
org/jruby/RubyArray.java:3226:in sort' /Users/rugger/Documents/acme/app/models/weekly_schedule.rb:24:in
each_out_of_office_time’
org/jruby/RubyRange.java:445:in `each’
Anyone have any idea whats going on? Either I’m missing something
completely obvious or I’m running into a JRuby bug. I’m using 1.6.7 in
1.9 mode.