10 Things Every Java Programmer Should Know About Ruby

Here's a nice concise presentation by Jim Weirich on the cool bits of Ruby.



I love this part that demonstrates the message based behavior of Ruby.




class VCR
def initialize
@messages = []
end
def method_missing(method, *args, &block)
@messages << [method, args, block]
end
def play_back_to(obj)
@messages.each do |method, args, block|
obj.send(method, *args, &block)
end
end
end

vcr = VCR.new
vcr.sub!(/Java/) { "Ruby" }
vcr.upcase!
vcr[11,5] = "Universe"
vcr << "!"

string = "Hello Java World"
puts string

vcr.play_back_to(string)
puts string



This prints out:




Hello Java World
HELLO RUBY Universe!



This is like nuke powered dynamic proxies. My brain swirls just thinking of the possibilities.

Comments

Popular posts from this blog

Shark Crackers

Running roughshod or ripshod

Axis, Axes, Axii?