I’m new to ruby world and i’m currently studying it. I have read over the google about nil object, but still can`t figure out what it is ?
Can anyone explain me in more details or share some link for further reading ?
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.
nilis the one and only instance of theNilClassclass. It doesn’t have any special behavior (other than the fact that it’s interpreted as false in a boolean context (e.g. in anifcondition), as Andrew Grimm helpfully pointed out). The purpose ofnilis to signify “no result”.For example a method which is supposed to find an item meeting a certain condition would return
nilif there is no item that meets the condition. Or accessing theith element of an array which has less thanielements will returnnil.It has a similar purpose to the null pointer in other languages, except that you can call
Objectmethods (i.e. methods which are defined on every object) on it without causing an exception.