Thursday 15 April 2010

Any way to reset a variable in ruby to its original value -



Any way to reset a variable in ruby to its original value -

let's declared variable @counter=0 in initialize method, , in part of code, want reset 1 time again original value. though can manually @counter=0, want know if there way reset original assigned value. example: @counter.reset

def initialize @counter = 0 ... end def first @some_string.each |f| if f == '' @counter += 1 end @counter = 0 # want alter here end end

variables aren't objects in ruby, can't tell them anything. there 2 things can variable: assign , dereference it.

ruby

No comments:

Post a Comment