I have this piece of Ruby code:
HTTPCLIENT = HTTPClient.new
def read_page(url)
HTTPCLIENT.get(url).body
end
The HTTPClient object is being created and declared as a constant, and thus it can be accessible by methods.
I would do this by declaring it as a global variable ($) or as a class variable (@), but I'm not sure if it's actually wrong the way it is.
I don't declare objects as variables because, well, their memory contents can vary. I only use constants to declare simple types (strings, numbers) or classes and modules. But objects? I'm not sure about it.
My question is: is this a bad code or it's just me? If so, then why do you think is a bad code?