Keeping the Sabbath (more thoughts on meta-coding)

T

Trans

Previously I entertained a Meta module, or using ObjectSpace for these
meta-coding commands. But thats a bit wordy. Today I thought about how
these specific commands are kind of sacred. Then I thought global vars
are kind of like that too. So:

$id = lambda{ |obj| Kernel.instance_method:)object_id).bind(obj).call
}
$class = lambda{ |obj| Kernel.instance_method:)class).bind(obj).call
}
$dup = lambda{ |obj| Kernel.instance_method:)dup).bind(obj).call }

class X
def object_id ; "sabatoge" ; end
def class ; "sabatoge" ; end
def dup ; "sabatoge" ; end
end

x = X.new

p x.object_id
p x.class
p x.dup

p $id[x]
p $class[x]
p $dup[x]

It's concise and we avoid keywords and cluttering the object's method
namespace.

You thoughts on "holy" commands?

T.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top