Ruby has a <<
method used for array and string concatenation, affectionately called the “shovel operator.” It can also be used to add methods to a class, like so:
class MyClass
class << self
def print_foo
puts 'foo'
end
end
end
MyClass.print_foo
# > foo
All the methods defined between class << self
and end
will be “self methods” on the Ruby object. (C# or Java would call them “static” methods; they belong to the class, not the instance.)
Anyway, defining constants inside the shovel operator works strangely. Continue reading “Constant shoveling”