LoginSignup
1
1

More than 5 years have passed since last update.

1.9.2p290のleap?の動き

Posted at

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

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 らへんにあた…

1
1
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
1
1