Help us understand the problem. What is going on with this article?

1.9.2p290のleap?の動き

More than 5 years have passed since last update.

触ってるプロジェクト内でバグ見つけた時に挙動が気になったので調べたメモ。

Date.leap?に文字列が渡せる

require 'date'
Date.leap? "hoge" #=> false

ruby1.9.2の中

lib/date.rb
def self.gregorian_leap? (y) y % 4 == 0 && y % 100 != 0 || y % 400 == 0 end
class << self; alias_method :leap?, :gregorian_leap? end

%メソッドが動いておった

ruby1.9.3では

require 'date'
Date.leap? "hoge"
#=> TypeError: can't convert Fixnum into String
#        from (irb):3:in `+'
#        from (irb):3:in `leap?'
#        from (irb):3
#        from /Users/mori_daisuke/.rbenv/versions/1.9.3-p484/bin/irb:12:in `<main>'

メソッド探したら ext/date/date_core.c らへんにあた…

freee
スモールビジネスのバックオフィス業務をテクノロジーで自動化し、日本のスモールビジネスを元気にする
http://www.freee.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away