What does map(&:name) mean in Ruby?

I found this code in a RailsCast: def tag_names @tag_names || tags.map(&:name).join(‘ ‘) end What does the (&:name) in map(&:name) mean? 16 s 16 It’s shorthand for tags.map(&:name.to_proc).join(‘ ‘) If foo is an object with a to_proc method, then you can pass it to a method as &foo, which will call foo.to_proc and use that … Read more

What’s the difference between equal?, eql?, ===, and ==?

I am trying to understand the difference between these four methods. I know by default that == calls the method equal? which returns true when both operands refer to exactly the same object. === by default also calls == which calls equal?… okay, so if all these three methods are not overridden, then I guess … Read more

Behaviour of increment and decrement operators in Python

I notice that a pre-increment/decrement operator can be applied on a variable (like ++count). It compiles, but it does not actually change the value of the variable! What is the behavior of the pre-increment/decrement operators (++/–) in Python? Why does Python deviate from the behavior of these operators seen in C/C++? 1Best Answer 11 ++ … Read more

What are bitwise shift (bit-shift) operators and how do they work?

I’ve been attempting to learn C in my spare time, and other languages (C#, Java, etc.) have the same concept (and often the same operators) … What I’m wondering is, at a core level, what does bit-shifting (<<, >>, >>>) do, what problems can it help solve, and what gotchas lurk around the bend? In … Read more

Is there a “null coalescing” operator in JavaScript?

Is there a null coalescing operator in Javascript? For example, in C#, I can do this: String someString = null; var whatIWant = someString ?? “Cookies!”; The best approximation I can figure out for Javascript is using the conditional operator: var someString = null; var whatIWant = someString ? someString : ‘Cookies!’; Which is sorta … Read more