hoodwink.d enhanced


Koichi's Brief Ruby Certification #

by why in bits

Koichi Sasada says if you can predict the correct output of the following, you are a great Ruby hacker. Man, that’s true!

 Const = :top
 class C
   Const = :C

 C.instance_eval %{p Const}
 C.instance_eval  {p Const}
 C.module_eval   %{p Const}
 C.module_eval    {p Const}
 C.class_eval    %{p Const}
 C.class_eval     {p Const}
 eval            %{p Const}
 eval             {p Const}

Even if you don’t get the answers right, I will call you a great Ruby hacker if you can explain it. (As usual: ~sasada.)

said on 30 Dec 2005 at 13:23

Heh, bit of a trick question.


require 'base64'
print Base64.decode64(<<EOS)
said on 30 Dec 2005 at 13:31

Oh yeah, I forgot to add:


require 'base64'
print Base64.decode64(<<EOS)
said on 30 Dec 2005 at 13:33

...and now I left off the EOS. What is my problem to-day?

said on 30 Dec 2005 at 15:05
damn I got it right till the last one :( Actually I think that:
class String
 def rot13
  tr "a-z", "n-za-m" 
"ybbxhc ehyrf sbe pbafgnagf ner onq, gurl fubhyq orunir yvxr pynff inevnoyrf, v.r qlanzvp if yrkvpny ".rot13
said on 30 Dec 2005 at 15:31

require ‘base64’ puts Base64.decode64(“SSBtaXNzZWQgbW9zdCBvZiB0aGUgb3V0cHV0LCBidXQgYXMgZm9yIGV4cGxh\nbmF0aW9uIEkgd2lsbCBoYXphcmQgYSBndWVzczogdGhlIGRpZmZlcmVuY2Ug\naW4gdGhlIHN0cmluZyBhbmQgY29kZS1ibG9jayBmb3JtIGNvbWVzIGZyb20g\ndGhlICJjbG9zdXJlIiBwcm9wZXJ0eSBvZiBjb2RlIGJsb2Nrcy4gIFdoZXJl\nYXMgdGhlIFN0cmluZyBldmFsIGRvZXNuJ3QgaW5oZXJpdCBhbnl0aGluZyBm\ncm9tIHRoZSBvdXRlciBiaW5kaW5nIHNvIHRoZSBvdGhlciAoOnRvcCkgQ29u\nc3QgdGFrZXMgZWZmZWN0Lgo=\n”)

said on 30 Dec 2005 at 15:40

Qlznzvp fpbcvat vf nyzbfg nyjnlf onq arjf, VZB .

I mean, IIRC McCarthy considered it an implementation mistake in his first lisps, even.

said on 30 Dec 2005 at 15:43

cilibrar: You may want to mark that as code so it doesn’t get smartquoted by RedCloth.

said on 30 Dec 2005 at 16:16
Thanks for the tip MenTaLguY! Great monad article, too, that is the only reason I could even begin to explain this.
require 'base64' puts Base64.decode64(&lt;&lt;EOF) SSBtaXNzZWQgbW9zdCBvZiB0aGUgb3V0cHV0LCBidXQgYXMgZm9yIGV4cGxh bmF0aW9uIEkgd2lsbCBoYXphcmQgYSBndWVzczogdGhlIGRpZmZlcmVuY2Ug aW4gdGhlIHN0cmluZyBhbmQgY29kZS1ibG9jayBmb3JtIGNvbWVzIGZyb20g dGhlICJjbG9zdXJlIiBwcm9wZXJ0eSBvZiBjb2RlIGJsb2Nrcy4gIFdoZXJl YXMgdGhlIFN0cmluZyBldmFsIGRvZXNuJ3QgaW5oZXJpdCBhbnl0aGluZyBm cm9tIHRoZSBvdXRlciBiaW5kaW5nIHNvIHRoZSBvdGhlciAoOnRvcCkgQ29u c3QgdGFrZXMgZWZmZWN0Lgo=<br> EOF
said on 30 Dec 2005 at 16:21
How come &lt; shows a less-than in the preview comment page but then changes to unspiritted form in the final post?

I seem to have dejiggered my formatting once again, not even mentioning the
... I guess Why has to fix it now I can’t figure it out.

said on 30 Dec 2005 at 16:33


said on 30 Dec 2005 at 17:33

cilibrar: Basically the JS-driven RedCloth preview is slightly broke. Known issue for a while. Just have faith, you needn’t escape your lt’s in code.

said on 30 Dec 2005 at 17:37

The magic recipe is to enclose your blocks of code in <pre><code>...&lt/code></pre>

That gives you code-formatting, as well as the nifty scrollbars when your paste gets too wide.

said on 30 Dec 2005 at 17:39

Beans. Missed a semicolon. But you get the idea.

On another note, isn’t this cool? We are all here with our secret Ruby decoder rings!

It’s like we are all 11 years old again, with the cereal boxes and the proofs of purchase.

said on 30 Dec 2005 at 21:04

mentalguy, I agree with the idea that if it is the only available thing it would be an error, but having both in a language seems the best thing to me, just like CL does.

said on 31 Dec 2005 at 13:17

I dont get why none of the post above are related to the actual proposed Brief Ruby Certification ???

Could I say it was a trick asking for the output as the code does not output anything but only returns value. of course, using irb you can see the return value outputed…

that said, I’m very wish I could explain all of it, but I actually never use those methods and I would need to read about it first. I also would like to have the % explained to me. and is it normal the last instruction raise an ArgumentError ???

I really thought

C.instance_eval returns :top because

C.class == Class not C

but C.new.instance_eval returns :top as well, so I am very confused.

said on 31 Dec 2005 at 13:24

what’s the buzz of encoding your answers ? what’s the idea behing a blog/forum do you think ?

said on 31 Dec 2005 at 15:16

MouseHole decoder ring.

said on 02 Jan 2006 at 10:03

This is off topic, but I get this JavaScript errors when I load this page (Firefox 1.5, Windows)

Error: Error in parsing value for property ‘font-size’. Declaration dropped. Source File: http://redhanded.hobix.com/site.css Line: 319

Error: Unknown property ‘filter’. Declaration dropped. Source File: http://redhanded.hobix.com/site.css Line: 327

Error: timerOut is not defined Source File: http://redhanded.hobix.com/js/liveUpdater.js Line: 151

said on 02 Jan 2006 at 22:57

"Yeah, grr on the last question. That's what I get
for being cocky and rushing through. :P

And is there a good writeup somewhere on the
difference between constant and class-var

Comments are closed for this entry.