This Week on Github: Stupid Ruby Tricks
Ruby is a very dynamic language. You can turn the language inside out, give objects a frontal lobotomy, and stitch the whole thing back together again, all at runtime. Here are some examples.
Wednesday, July 15th, 2009
Ruby is a very dynamic language. You can turn the language inside out, give objects a frontal lobotomy, and stitch the whole thing back together again, all at runtime.
Given its dynamism, many people have found abnormal even scary techniques to manipulate the behavior of Ruby. This week, let’s catalog just some of those libraries.
Sit back and prepare to be amazed.
Superators
Jay Phillips, author of the fantastic Adhearsion VoIP Ruby library, created a great hack called superators (http://github.com/jicksta/superators) to add operators to Ruby. Instead of the few operators the Ruby parser normally supports, like /
or +
, you can use any operator (or combination thereof) to manipulate values.
For example, if you wanted to define a superator +<
to conjoin one string to another and reverse the resulting composite string, you could do something like this:
...
Please log in to view this content.
Read More
- The Party of Gno
- Intro to CUDA
- Helpful Tools for Software Developers
- The Github Hall of Fame
- Book'em, Github.
|