Get the latest tech news

There is no such thing as a global method in Ruby


What Ruby’s top-level methods actually are, who they belong to and how they are namespaced

A few days ago, a curious question was asked on /r/ruby, which can be boiled down to this: How are the methods of the Kernel module available in the top-level scope? This is a clear and consistent system… Which might sometimes lead to extremely weird quirks with the metaprogramming code, which checks for some method’s presence by name and changes the behavior depending on it. (:avatar_url) —and in some completely unrelated place, a helper module was included into the global scope, which made all objects to have avatar_url method… But not the one that would be expected there in the serialization code.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of thing

thing

Photo of ruby

ruby

Photo of global method

global method

Related news:

News photo

Netflix Wiped Most of Its “Palestinian Stories” Collection — and Erased the Whole Thing in Israel | Nikita Mazurov

News photo

The Thing: Remastered's first look at gameplay looks suitably terrifying

News photo

Colorful cars are becoming a thing of the past