Ruby lib/irb/easter-egg.rb
github.com
github.com
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.)
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.
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)'IRB.send(:easter_egg, :dancing)
And you should always get the animated one.
gem install reline
ruby yourfile.rb
It is a nice ascii demo of a ruby turning around