Ruby notation

Ok, we all knew that Ruby is very dynamic. The fun part starts if you start thinking about your own notation. It turns out, it’s even more loose and fast than I thought. So consider this:

obj =

obj.do_something(params) # this calls the method with parameters
obj::do_something(params) # this is actually the same thing (calls do_something)

obj.do_something:cool # and this call the method with the parameter :cool
obj::do_something:cool # ok, and now it’s getting funny

obj.Will_do # uppercase method names also work on objects

# so, for classes

Klass.do_something # this will call the class method, of course
Klass::do_something # and this also calls the method
Klass.UpperCase # and this calls a class method with an upper case name
Klass::UpperCase # BUT THIS CALLS THE CONSTANT (go, figure…)

The nice thing is that you can really start thinking of your own notation for things. Still, it’s great weirdness notheless…


Comments are closed.

Blog at

Up ↑

%d bloggers like this: