From: "Iñaki Baz Castillo" Date: 2011-05-01T06:58:57+09:00 Subject: Re: Why defining a constant in a method is not allowed but using self.class.const_set is allowed? 2011/4/30 7stud -- : > "Iñaki Baz Castillo" wrote in post #995996: >> >> Ok. Then one question more: why is not possible to reassing a value to >> a constant > > Why do you want to change a *constant*?  ruby has variables for that. Because it's more efficient. Consider this example: module M class C KAKA = 123 def self.kaka @kaka ||= 123 end end end # Let's initialize @kaka: M::C.kaka => 123 $kaka = 123 -------------------------------- Benchmark.realtime { 10000000.times { M::C::KAKA } } => 0.9098186492919922 Benchmark.realtime { 10000000.times { M::C.kaka } } => 1.9608278274536133 Benchmark.realtime { 10000000.times { $kaka } } => 0.9143557548522949 -- Iñaki Baz Castillo