From: John Joyce Date: 2007-03-16T00:11:03+09:00 Subject: Re: What does this do? : Looks like a ternary operator (you know binary and unary operators, this is the only ternary I've ever seen) exists in C and C like languages such as PHP conditional_statement ? true_result : false_result if () a else b written as if_condition ? result_a : result_b one of the less lovely things to read in C like languages, but after you get used to it, it is actally a space saver. It is relly just an conditional with two possible outcomes Looks llike the code first checks to see if the user exists, if the user doesn't exist, you get an error message of some sort. after that, user.id is compared to recipient_id if they're the same, sender, else recipient what it's for? who knows. some kind of validation and direction. On Mar 15, 2007, at 11:50 PM, jko170 wrote: > Looking at this piece of code, what does the colon do? > > def partner_to(user) > raise ArgumentError unless user > user.id == recipient_id ? sender : recipient > end > > I got the code from this rails post: > http://groups.google.com/group/rubyonrails-talk/browse_thread/ > thread/7fdccddde9b97ffc/6112294580b9e0ce?lnk=gst&q=internal > +mail&rnum=1#6112294580b9e0ce > > I'm just asking because I've never seen the colon used before. > >