If Array and String are class definitions, how are these things defined?
def whatever(some_input)
some_input = Array(some_input)
end
How does that get invoked? Can we add this behaviour to our own classes, or is this only for core classes?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
They’re actually methods on Kernel:
And Object includes Kernel so these methods are available everywhere. You can make methods whose names begin with an upper case letter, it just isn’t that common.
Nokogiri does similar things with the
Nokogiri::HTMLandNokogiri::XMLconstructors. For example, in Nokogiri you will find this:so
HTMLis just a standard method with non-standard name.