In Ruby, a set can be initialized by Set[1,2,3]
So can an array: Array[1,2,3]
Is it possible to write some code to do the same thing to my own classes?
Or it’s just a language feature for only a few built-in 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.
In Ruby,
foo[bar, baz]is just syntactic sugar forfoo.[](bar, baz). All you need is a method named[].By the way: you just need to look at the documentation, e.g. for
Set:That’s the documentation right there.
Basically, all you need is