x
Loading
 Loading
Hello, Guest | Login | Register

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.

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.

Not Yet a Member?

Register with LinuxMagazine.com and get free access to the entire archive, including:

  • Hands-on Content
  • White Papers
  • Community Features
  • And more.
Already a Member?
Log in!
Username

Password

Remember me

Forgotten your password?
Forgotten your username?
Read More
  1. The Party of Gno
  2. Intro to CUDA
  3. Helpful Tools for Software Developers
  4. The Github Hall of Fame
  5. Book'em, Github.
Follow linuxdlsazine