Koichi's Brief Ruby Certification #
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 end 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.)
MenTaLguY
Heh, bit of a trick question.
spoilers:
MenTaLguY
Oh yeah, I forgot to add:
spoiler:
MenTaLguY
...and now I left off the
EOS
. What is my problem to-day?riffraff
cilibrar
require ‘base64’ puts Base64.decode64(“SSBtaXNzZWQgbW9zdCBvZiB0aGUgb3V0cHV0LCBidXQgYXMgZm9yIGV4cGxh\nbmF0aW9uIEkgd2lsbCBoYXphcmQgYSBndWVzczogdGhlIGRpZmZlcmVuY2Ug\naW4gdGhlIHN0cmluZyBhbmQgY29kZS1ibG9jayBmb3JtIGNvbWVzIGZyb20g\ndGhlICJjbG9zdXJlIiBwcm9wZXJ0eSBvZiBjb2RlIGJsb2Nrcy4gIFdoZXJl\nYXMgdGhlIFN0cmluZyBldmFsIGRvZXNuJ3QgaW5oZXJpdCBhbnl0aGluZyBm\ncm9tIHRoZSBvdXRlciBiaW5kaW5nIHNvIHRoZSBvdGhlciAoOnRvcCkgQ29u\nc3QgdGFrZXMgZWZmZWN0Lgo=\n”)
MenTaLguY
Qlznzvp fpbcvat vf nyzbfg nyjnlf onq arjf, VZB .
I mean, IIRC McCarthy considered it an implementation mistake in his first lisps, even.
MenTaLguY
cilibrar: You may want to mark that as code so it doesn’t get smartquoted by RedCloth.
cilibrar
require 'base64' puts Base64.decode64(<<EOF) SSBtaXNzZWQgbW9zdCBvZiB0aGUgb3V0cHV0LCBidXQgYXMgZm9yIGV4cGxh bmF0aW9uIEkgd2lsbCBoYXphcmQgYSBndWVzczogdGhlIGRpZmZlcmVuY2Ug aW4gdGhlIHN0cmluZyBhbmQgY29kZS1ibG9jayBmb3JtIGNvbWVzIGZyb20g dGhlICJjbG9zdXJlIiBwcm9wZXJ0eSBvZiBjb2RlIGJsb2Nrcy4gIFdoZXJl YXMgdGhlIFN0cmluZyBldmFsIGRvZXNuJ3QgaW5oZXJpdCBhbnl0aGluZyBm cm9tIHRoZSBvdXRlciBiaW5kaW5nIHNvIHRoZSBvdGhlciAoOnRvcCkgQ29u c3QgdGFrZXMgZWZmZWN0Lgo=<br> EOF
cilibrar
<
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.
Danno
MenTaLguY
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.
MenTaLguY
The magic recipe is to enclose your blocks of code in <pre><code>...</code></pre>
That gives you code-formatting, as well as the nifty scrollbars when your paste gets too wide.
MenTaLguY
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.
riffraff
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.
somekool
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.
somekool
what’s the buzz of encoding your answers ? what’s the idea behing a blog/forum do you think ?
why
MouseHole decoder ring.
Zeljko
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
twifkak
Comments are closed for this entry.