Ruby block and unparenthesized arguments

It’s because you’re calling pp x.map and passing a block to pp (which ignores it) As explained in the Programming Ruby book Braces have a high precedence; do has a low precedence So, effectively, braces tie to the function call closest to them (x.map) whereas do binds to the furthest away (pp). That’s a bit … Read more

Using do block vs braces {}

Ruby cookbook says bracket syntax has higher precedence order than do..end Keep in mind that the bracket syntax has a higher precedence than the do..end syntax. Consider the following two snippets of code: 1.upto 3 do |x| puts x end 1.upto 3 { |x| puts x } # SyntaxError: compile error Second example only works … Read more

rbenv not changing ruby version

Check that PATH contains $HOME/.rbenv/shims and $HOME/.rbenv/bin $ env | grep PATH Also check that you have the following in your ~/.bash_profile if using bash or ~/.zshenv if using zsh export PATH=”$HOME/.rbenv/bin:$PATH” eval “$(rbenv init -)” NOTE: Make sure it’s the last setting in your ~/.bash_profile . I ran into an issue where I installed … Read more

Dynamic constant assignment

Your problem is that each time you run the method you are assigning a new value to the constant. This is not allowed, as it makes the constant non-constant; even though the contents of the string are the same (for the moment, anyhow), the actual string object itself is different each time the method is … Read more

The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256

AWS4-HMAC-SHA256, also known as Signature Version 4, (“V4”) is one of two authentication schemes supported by S3. All regions support V4, but US-Standard¹, and many — but not all — other regions, also support the other, older scheme, Signature Version 2 (“V2”). According to http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html … new S3 regions deployed after January, 2014 will only … Read more

Difference between “and” and && in Ruby?

and is the same as && but with lower precedence. They both use short-circuit evaluation. WARNING: and even has lower precedence than = so you’ll usually want to avoid and. An example when and should be used can be found in the Rails Guide under “Avoiding Double Render Errors”.

Ruby Gem install Json fails on Mavericks and Xcode 5.1 – unknown argument: ‘-multiply_definedsuppress’

I am encountering the exact same problem after updating Xcode to 5.1 and news from Apple aren’t good. From Xcode 5.1 Release Notes: The Apple LLVM compiler in Xcode 5.1 treats unrecognized command-line options as errors. This issue has been seen when building both Python native extensions and Ruby Gems, where some invalid compiler options … 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