Computer Science Canada A tiny bit of metaprogramming magic |
Author: | wtd [ Sun Dec 14, 2008 3:13 am ] | ||||||||
Post subject: | A tiny bit of metaprogramming magic | ||||||||
A simple demo:
Now:
Will yield:
|
Author: | gianni [ Sun Dec 14, 2008 3:19 am ] |
Post subject: | RE:A tiny bit of metaprogramming magic |
Tres cool, this kind of stuff makes me feel all warm and fuzzy inside. |
Author: | gianni [ Sun Dec 14, 2008 3:44 am ] | ||||||||
Post subject: | Re: A tiny bit of metaprogramming magic | ||||||||
My small contribution based entirely off of wtd's code:
Demo:
Yields:
|
Author: | wtd [ Sun Dec 14, 2008 3:48 am ] |
Post subject: | RE:A tiny bit of metaprogramming magic |
Most excellent. |
Author: | Insectoid [ Sun Dec 14, 2008 4:40 pm ] |
Post subject: | RE:A tiny bit of metaprogramming magic |
tres confused. I am completely lost, though with under a week (or has it been a week?) of Ruby experience, that is to be expected. What does class <<object do? What does 'delegate' do? |
Author: | wtd [ Sun Dec 14, 2008 5:35 pm ] | ||||
Post subject: | RE:A tiny bit of metaprogramming magic | ||||
In Ruby classes are objects. By using "class <<Object" I am working within the context of the class rather than instances of it. As for delegate, it is just a method, but one on the class, rather than instances of it. What it does is to define a method on instances of the class.
The equivalent manual code would be:
|
Author: | Cowzero [ Mon Feb 18, 2019 2:33 am ] |
Post subject: | RE:A tiny bit of metaprogramming magic |
Is a great knowledge |