たけ(tk)です

最近またしてもこの手のバグではまってしまいました。

--

TUKIMEI = {
  :nihongo => ["睦月","如月","弥生"],
  :eigo    => ["January","February","March"]  
}#.freeze_all

def tukino_namaeto_nissuu( year,month, lang=:nihongo )
  name = TUKIMEI[lang][month-1]
  days = [31,28,31,30][month-1]
  if ( month == 2 ) &&
     ( Time.local(year, 12,31).yday == 366 )
    name << "(leap)"
    days = 29 
  end
  return [name,days]          
end

p tukino_namaeto_nissuu(2002,2)
p tukino_namaeto_nissuu(2003,2)
p tukino_namaeto_nissuu(2004,2)
p tukino_namaeto_nissuu(2005,2)

--

これを防ぐために次のようなものはどうでしょうか?

class Array
  def freeze_all
    each{|i|
     (defined? i.freeze_all) ? i.freeze_all : i.freeze
    }
    freeze
  end
end
class Hash
  def freeze_all
    each{|k,v|
     (defined? k.freeze_all) ? k.freeze_all : k.freeze
     (defined? v.freeze_all) ? v.freeze_all : v.freeze
    }
    freeze
  end
end

TUKIMEI = {
  :nihongo => ["睦月","如月","弥生"],
  :eigo    => ["January","February","March"]  
}.freeze_all
	・・・

Take_tk = KUMAGAI Hidetake
たけ(tk)=熊谷秀武