Forwarding Forwarding - 1 year ago 117
Ruby Question

How to uninitialize/undefine a variable in Ruby so I don't get warnings in console?

I keep getting this warning in console, it's cluttering my

output, and I want it gone:

d.rb:24: warning: previous definition of VariableA was here
d.rb:86: warning: already initialized constant VariableA

Tried doing this after using them:

VariableA = nil
VariableB = nil

Important note: These variables are re-used in a loop.

Answer Source

In ruby whenever you use a capital letter first letter you are creating a constant. You will be warned when it is redefined.

For example

  ThisIsAlsoAConstant = "The answer!"


  def a_method
   @this_is_a_member_variable = true
   this_is_a_local_variable = true


If you create a constant inside a method, you will get re-definition error the second time you call the method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download