How to dynamically define a class method which will refer to a local variable outside?

Class methods don’t really exist in Ruby, they are just singleton methods of the class object. Singleton methods don’t really exist, either, they are just ordinary instance methods of the object’s singleton class. Since you already know how to define instance methods (using Module#define_method), you already know everything you need to know. You just need … Read more

How do I create a memory leak in JavaScript?

You’re not keeping the element you’ve created around and referenced anywhere – that’s why you’re not seeing the memory usage increase. Try attaching the element to the DOM, or store it in an object, or set the onclick to be a different element that sticks around. Then you’ll see the memory usage skyrocket. The garbage … Read more

What are free variables?

Free variables are simply the variables that are neither locally declared nor passed as parameter. Source : In computer programming, the term free variable refers to variables used in a function that are not local variables nor parameters of that function.1 The term non-local variable is often a synonym in this context. In javascript closures, … Read more

Groovy : Closures or Methods

I only use closures where I need them, i.e. I use methods by default. I do this because Methods are simpler than closures. Closures have a delegate, an owner, retain access to variables that were in their local scope when created (what you call “free variables”). By default method calls within a closure are resolved … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)