# Function to flush the variable

**URL:** <https://www.ruby-forum.com/t/function-to-flush-the-variable/156752>\
**Category:** Ruby\
**Created:** [January 2, 2009, 12:38pm UTC](https://www.ruby-forum.com/t/function-to-flush-the-variable/156752 "2009-01-02T12:38:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![amitjhs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amitjhs](https://www.ruby-forum.com/u/amitjhs)\
**Post date:** [January 2, 2009, 12:38pm UTC](https://www.ruby-forum.com/t/function-to-flush-the-variable/156752/1 "2009-01-02T12:38:45Z")

</div>

Hi,  
Is there any function to flush the value from a variable. I am facing  
problem while assiging a value to Ruby variable.

---

<div class="post-metadata">

**Author:** ![amitjhs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amitjhs](https://www.ruby-forum.com/u/amitjhs)\
**Post date:** [January 2, 2009, 12:44pm UTC](https://www.ruby-forum.com/t/function-to-flush-the-variable/156752/2 "2009-01-02T12:44:02Z")

</div>

On Fri, Jan 2, 2009 at 1:37 PM, Amit A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ## Hi, Is there any function to flush the value from a variable. I am facing problem while assiging a value to Ruby variable.
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

What do you mean by flush? Remove the current value?  
my\_var = nil  
should do that

---

<div class="post-metadata">

**Author:** ![amitjhs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amitjhs](https://www.ruby-forum.com/u/amitjhs)\
**Post date:** [January 2, 2009, 12:50pm UTC](https://www.ruby-forum.com/t/function-to-flush-the-variable/156752/3 "2009-01-02T12:50:32Z")

</div>

I am trying to use following code

Status=sheet1.getCellByPosition(5, I).Formula  
ie.text\_field(:name, “FieldName”).value =Status

and it works fine, but On itetrating this piece of code for multiple I/  
Ps, variable ‘name’, retains its old value for some of the cases. I  
identified this as a cache problem. Please suggest if there any flush  
() type function or action in Ruby/watir to clear the garbage value.

actually there is function in C, i.e. flush which clears the garbage  
value.

Andrew T. wrote:

> On Fri, Jan 2, 2009 at 1:37 PM, Amit A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > ## Hi, Is there any function to flush the value from a variable. I am facing problem while assiging a value to Ruby variable.
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> What do you mean by flush? Remove the current value?  
> my\_var = nil  
> should do that

---

<div class="post-metadata">

**Author:** ![amitjhs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amitjhs](https://www.ruby-forum.com/u/amitjhs)\
**Post date:** [January 2, 2009, 1:04pm UTC](https://www.ruby-forum.com/t/function-to-flush-the-variable/156752/4 "2009-01-02T13:04:01Z")

</div>

On Fri, Jan 2, 2009 at 1:49 PM, Amit A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > > problem while assiging a value to Ruby variable.

A ‘variable’ with an uppercase first letter is actually a constant in  
ruby  
and you can only assign to it once.  
Change ‘Status’ to ‘status’ and you should see it work

–  
Andrew T.  
[http://ramblingsonrails.com](http://ramblingsonrails.com)  
[http://www.linkedin.com/in/andrewtimberlake](http://www.linkedin.com/in/andrewtimberlake)

“I have never let my schooling interfere with my education” - Mark Twain

---

<div class="post-metadata">

**Author:** ![amitjhs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amitjhs](https://www.ruby-forum.com/u/amitjhs)\
**Post date:** [January 2, 2009, 1:11pm UTC](https://www.ruby-forum.com/t/function-to-flush-the-variable/156752/5 "2009-01-02T13:11:03Z")

</div>

Amit A. wrote:

> actually there is function in C, i.e. flush which clears the garbage  
> value.

In ruby there is a method IO#flush which flushes an output stream the  
same way  
flush in C does. This has nothing to do with variables, however.

HTH,  
Sebastian

---

<div class="post-metadata">

**Author:** ![amitjhs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amitjhs](https://www.ruby-forum.com/u/amitjhs)\
**Post date:** [January 2, 2009, 3:08pm UTC](https://www.ruby-forum.com/t/function-to-flush-the-variable/156752/6 "2009-01-02T15:08:23Z")

</div>

> > Andrew T. wrote:

> A ‘variable’ with an uppercase first letter is actually a constant in ruby  
> and you can only assign to it once.  
> Change ‘Status’ to ‘status’ and you should see it work

In Ruby you can assign to a constant as many times as you like. You  
will be scolded for it, but it’s allowed.

irb(main):001:0\> IMA\_CONST = “foo”  
=\> “foo”  
irb(main):002:0\> IMA\_CONST = “bar”  
(irb):2: warning: already initialized constant IMA\_CONST  
=\> “bar”  
irb(main):003:0\> IMA\_CONST = “baz”  
(irb):3: warning: already initialized constant IMA\_CONST  
=\> “baz”  
irb(main):004:0\> IMA\_CONST  
=\> “baz”

-Michael
