Calling a Method From a String With the Method’s Name in Ruby

To call functions directly on an object a = [2, 2, 3] a.send(“length”) # or a.public_send(“length”) which returns 3 as expected or for a module function FileUtils.send(‘pwd’) # or FileUtils.public_send(:pwd) and a locally defined method def load() puts “load() function was executed.” end send(‘load’) # or public_send(‘load’) Documentation: Object#public_send Object#send

What exactly is metaprogramming?

Metaprogramming refers to a variety of ways a program has knowledge of itself or can manipulate itself. In languages like C#, reflection is a form of metaprogramming since the program can examine information about itself. For example returning a list of all the properties of an object. In languages like ActionScript, you can evaluate functions … Read more

Python dictionary from an object’s fields

Note that best practice in Python 2.7 is to use new-style classes (not needed with Python 3), i.e. class Foo(object): … Also, there’s a difference between an ‘object’ and a ‘class’. To build a dictionary from an arbitrary object, it’s sufficient to use __dict__. Usually, you’ll declare your methods at class level and your attributes … Read more

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