What is Ruby’s double-colon `::`?

:: is basically a namespace resolution operator. It allows you to access items in modules, or class-level items in classes. For example, say you had this setup: module SomeModule module InnerModule class MyClass CONSTANT = 4 end end end You could access CONSTANT from outside the module as SomeModule::InnerModule::MyClass::CONSTANT. It doesn’t affect instance methods defined … Read more

Is there a conditional ternary operator in VB.NET?

Depends upon the version. The If operator in VB.NET 2008 is a ternary operator (as well as a null coalescence operator). This was just introduced, prior to 2008 this was not available. Here’s some more info: Visual Basic If announcement Example: Dim foo as String = If(bar = buz, cat, dog) [EDIT] Prior to 2008 … Read more

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

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 as the method’s block. The Symbol#to_proc method was originally added by ActiveSupport but has been integrated into Ruby 1.8.7. This is its implementation: class … Read more

What is the difference between ‘/’ and ‘//’ when used for division?

In Python 3.x, 5 / 2 will return 2.5 and 5 // 2 will return 2. The former is floating point division, and the latter is floor division, sometimes also called integer division. In Python 2.2 or later in the 2.x line, there is no difference for integers unless you perform a from __future__ import … Read more

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

I’m going to heavily quote the Object documentation here, because I think it has some great explanations. I encourage you to read it, and also the documentation for these methods as they’re overridden in other classes, like String. Side note: if you want to try these out for yourself on different objects, use something like … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)