Understanding message passing in Ruby

I saw a link on reddit comparing Python and Ruby. The article, surprisingly, wasn’t an infantile fan boy tirade. And it solidified some of my Ruby reading. One of the things I don’t always “read” when I look at Ruby is the concept of message passing. However the following snippet, I think, makes it very real.


class Foo

def something
puts "Hello"
end

end

f = Foo.new
f.send('something')
f.something

Both, ‘.send()’ and ‘.method’ result in the same thing.

In my mind, calling a method on an object is still pretty rooted in the Java idea that we inspect the object for something, whereas in Ruby we are passing a message to the object. The difference is subtle, but interesting.

About Nathan Powell

I am a middle aged technologist freak-ball.
This entry was posted in programming. Bookmark the permalink.

Comments are closed.