4 ms·
Ruby lib/irb/easter-egg.rb
- syspec 6y agoI stumbled onto this when looking at the ruby source code, anyone know how to trigger it?
- rafadc 6y agoJust copy the contents in a file and gem install reline ruby yourfile.rb It is a nice ascii demo of a ruby turning around
- q3k 6y agoOn Ruby 2.7+, run irb, type 'RubyVM', press tab twice.
- relyks 6y agoSuper cool, didn't know you could do that :)
- jbverschoor 6y agoYou have to try a few times to get the logo or dancing logo
- syspec 6y agoThanks! Very cool - here's a gif for the curious: https://media1.giphy.com/media/L0eN2GwpS7GOmv5Kk7/giphy.gif https://media1.giphy.com/media/L0eN2GwpS7GOmv5Kk7/giphy.gif
- relyks 6y agoRun irb and input 'IRB.send(:easter_egg)'. Also, if you have the downloaded source, you can just run the source file directly because of the last line of code.
- sdwolfz 6y agoHere's a one liner: ruby -r irb -e 'IRB.send(:easter_egg)' And in Docker you get a static image, but sometimes, randomly you get the dynamic one... docker run --rm -it ruby:2.7.1-alpine ruby -r irb -e 'IRB.send(:easter_egg)'
- derefr 6y agoA tangent, but: I've read and written a lot of Ruby—except never much of the stdlib, for some reason—and I've literally never seen anyone use the `private` pseudo-keyword in the Java-esque way it's used here (`private def foo...` on the same line), to the point that I didn't even realize that that was possible. I've always only seen these usages: • `private` on its own line with surrounding whitespace, treated as a section-break in the class, where it has a "mode-switch for all that follows" effect similar to `private:` in C++. • `private :foo` on a separate line after `def foo...`, where it's just acting as a standalone call to one of Class's "builder" DSL methods, like an `attr_reader` call. • `private\ndef foo` (rare), as if `private` were some Java-like annotation modifying just the following method (though this is really just the first mode-switching kind, and later methods will need a `public\n` "annotation" to go back.) Why is that? It seems startlingly obvious, once you see it done, that `private def ...` is the idiomatic way to use it. (After all, they bothered to make `def` return the symbolic name of the function you defined, just so you could chain it into class-builder-methods like this.)
- abhorrence 6y agodef returning the method name as a symbol wasn’t added until ruby 2.1, and doesn’t seem to have been compelling enough to cause people to change their ways.
- dragonwriter 6y ago> It seems startlingly obvious, once you see it done, that `private def ...` is the idiomatic way to use it. As you note that almost no one does it in Ruby, it is not the idiomatic way in Ruby. Idioms change slowly, and this wasn't supported for most of Ruby history.