C's static equivalent

K

KONTRA Gergely

Hi!

Is there something similar to C's static keyword?
I want a single function, which has to access and modify a permanent
variable. Any solution without bundling the function to a class?

Gergo
 
T

ts

K> Is there something similar to C's static keyword?
K> I want a single function, which has to access and modify a permanent
K> variable. Any solution without bundling the function to a class?

Use a closure

Guy Decoux
 
K

KONTRA Gergely

K> Is there something similar to C's static keyword?
K> I want a single function, which has to access and modify a permanent
K> variable. Any solution without bundling the function to a class?
Use a closure
Could you be more verbose? Eg. how to print out how many times a
function was called.

Gergo
 
T

ts

K> Could you be more verbose? Eg. how to print out how many times a

in ruby, yes. in english, no :)

K> function was called.

svg% cat b.rb
#!/usr/bin/ruby
def test1
a = 10
proc { a += 1; puts a }
end

class Object
define_method:)tt, test1)
end

tt
tt

uu = test1
uu[]
uu[]
svg%

svg% b.rb
11
12
11
12
svg%



Guy Decoux
 
J

Josef 'Jupp' Schugt

Saluton!

* Hal E. Fulton; 2003-08-07, 17:05 UTC:
It would be worthwhile for all of us to learn French in order to
learn more of your wisdom. :)

Si on ne doit pas répondre en français :->
As long as we are not required to answer in french ...

Gis,

Josef 'Jupp' Schugt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top