Constant Shuffle

1 · Jan Lelis · May 14, 2016, midnight
Today, another snippet from the category don't try at home, might have unforeseeable consequences! Constant assignment¹ is not permanent in Ruby, so it is perfectly valid to do this: module A end class B def initialize p 42 end end A, B = B, A # warning: already initialized constant A # warning: previous definition of A was here # warning: already initialized constant B # warning: previous definition of B was here A.new #=> #<B:0x00000002744008> # 42 ¹ As a side note: There is also ...