News for hackers. Stuff that matters.
Re:Ruby lib/irb/easter-egg.rb by derefr on Sunday July 12, 2020 @11:26AM (#23812042)
A 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.)

Re:Ruby lib/irb/easter-egg.rb by dragonwriter on Sunday July 12, 2020 @11:46AM (#23812174)
> 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.

Re:Ruby lib/irb/easter-egg.rb by abhorrence on Sunday July 12, 2020 @11:39AM (#23812125)
def 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.
Re:Ruby lib/irb/easter-egg.rb by sdwolfz on Sunday July 12, 2020 @07:01AM (#23810475)
Here'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)'
Re:Ruby lib/irb/easter-egg.rb by jsjohnst on Sunday July 12, 2020 @11:50AM (#23812213)
Make it:

IRB.send(:easter_egg, :dancing)

And you should always get the animated one.

Re:Ruby lib/irb/easter-egg.rb by sdwolfz on Sunday July 12, 2020 @12:30PM (#23812521)
Yes, can confirm it works without failure!
Re:Ruby lib/irb/easter-egg.rb by syspec on Sunday July 12, 2020 @02:57AM (#23809444)
I stumbled onto this when looking at the ruby source code, anyone know how to trigger it?
Re:Ruby lib/irb/easter-egg.rb by q3k on Sunday July 12, 2020 @04:24AM (#23809816)
On Ruby 2.7+, run irb, type 'RubyVM', press tab twice.
Re:Ruby lib/irb/easter-egg.rb by syspec on Sunday July 12, 2020 @06:03AM (#23810245)
Thanks! Very cool - here's a gif for the curious: https://media1.giphy.com/media/L0eN2GwpS7GOmv5Kk7/giphy.gif
Re:Ruby lib/irb/easter-egg.rb by jbverschoor on Sunday July 12, 2020 @05:12AM (#23810038)
You have to try a few times to get the logo or dancing logo
Re:Ruby lib/irb/easter-egg.rb by relyks on Sunday July 12, 2020 @04:33AM (#23809865)
Super cool, didn't know you could do that :)
Re:Ruby lib/irb/easter-egg.rb by relyks on Sunday July 12, 2020 @04:27AM (#23809831)
Run 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.
Re:Ruby lib/irb/easter-egg.rb by rafadc on Sunday July 12, 2020 @04:23AM (#23809811)
Just copy the contents in a file and

    gem install reline
    ruby yourfile.rb

It is a nice ascii demo of a ruby turning around