Ruby on iPod touchでDateクラスのバグ?

GoogleCalendarが提供するiCal形式のファイルをパースしようとして、Rubyのicalendarというライブラリを使ってみることにした。*1ためしにサンプルを書いて、ipod touchで動かそうとしたらエラー。ubuntuなら動いたのに。

# ruby calparse.rb
/opt/iphone//lib/ruby/1.8/date.rb:1508: [BUG] unexpected local variable
ruby 1.8.6 (2007-03-13) [arm-darwin]

zsh: abort      ruby calparse.rb

Dateオブジェクトがうまく生成できない? calparse.rbの内容はこれ。

require 'icalendar-1.0.2/lib/icalendar'

# Open a file or pass a string to the parser
cal_file = File.open("basic.ics")

# Parser returns an array of calendars because a single file
# can have multiple calendars.
cals = Icalendar.parse(cal_file)
cal = cals.first

# Now you can access the cal object in just the same way I created it
event = cal.events.first

puts "start: "
puts event.dtstart
puts "summary: " + event.summary

rubygemsを使っていないのはiPod touchrubygemsを動かしていない環境でも、rubyさえ動けばコードが動いてほしいからという理由です。

date.rbの1508行目あたりはこのへん

1492   # Create a new DateTime object corresponding to the specified
1493   # Commercial Date and hour +h+, minute +min+, second +s+.
1494   #
1495   # The 24-hour clock is used.  Negative values of +h+, +min+, and
1496   # +sec+ are treating as counting backwards from the end of the
1497   # next larger unit (e.g. a +min+ of -2 is treated as 58).  No
1498   # wraparound is performed.  If an invalid time portion is specified,
1499   # an ArgumentError is raised.
1500   #
1501   # +of+ is the offset from UTC as a fraction of a day (defaults to 0).
1502   # +sg+ specifies the Day of Calendar Reform.
1503   #
1504   # +y+ defaults to 1582, +w+ to 41, and +d+ to 5; this is the Day of
1505   # Calendar Reform for Italy and the Catholic countries.
1506   # The time values default to 0.
1507   def self.commercial(y=1582, w=41, d=5, h=0, min=0, s=0, of=0, sg=ITALY)
1508     unless (jd = valid_commercial?(y, w, d, sg)) &&
1509      (fr = valid_time?(h, min, s))
1510       raise ArgumentError, 'invalid date'
1511     end
1512     if String === of
1513       of = (zone_to_diff(of) || 0).to_r/86400
1514     end
1515     new!(jd_to_ajd(jd, fr, of), of, sg)
1516   end

ごく普通のrubyコードだと思うのだけれど...

エラーメッセージでぐぐってみたらまつもとさんが"[BUG] unexpected local variable"についてメーリングリストに投げていました。

touchでRubyを動かしても不安定だということがわかっただけでした。

今日はエラーコードをいっぱい見た一日でした。

追記

去年の10月にid:faultierが書いてた記事を発見した。メモリがたりないのか。

*1:Cocoa?それおいしそうだね!