Previous Next

Ruby is more better than your programming language · 506 days ago

I am getting used to the ruby syntax. And beginning to really enjoy the ability to reopen any class / module at any time. Here is a completely useless example of how you can mess with your co-workers and generally wreak havoc.

Goldfish code:


2 + 3 # => 5
2 + 2 # => 4
class Fixnum
  alias :plus :+
  def +(i)
    return "goldfish"  if to_i==2 && i.to_i==2
    to_i.plus i
  end
end
2 + 3 # => 5
2 + 2 # => "goldfish"

Coming soon—> an example of good magic from actual source. I am rewriting something that a co-worker wrote that magically defines a set of classes from an existing namespace into a new magic namespace. Including rewriting ActiveRecord subclasses to use the namespace as a table name prefix. It is currently a set of nested eval calls. I am going to make it more object oriented and more “ruby-esque”.

Comments