2011/4/30 7stud -- <bbxx789_05ss / yahoo.com>:
> "Iaki Baz Castillo" <ibc / aliax.net> 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



-- 
Iaki Baz Castillo
<ibc / aliax.net>