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”.

In Ruby, how do I skip a loop in a .each loop, similar to ‘continue’ [duplicate]

Use next: (1..10).each do |a| next if a.even? puts a end prints: 1 3 5 7 9 For additional coolness check out also redo and retry. Works also for friends like times, upto, downto, each_with_index, select, map and other iterators (and more generally blocks). For more info see http://ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html#UL.

Should I use alias or alias_method?

alias_method can be redefined if need be. (it’s defined in the Module class.) alias‘s behavior changes depending on its scope and can be quite unpredictable at times. Verdict: Use alias_method – it gives you a ton more flexibility. Usage: def foo “foo” end alias_method :baz, :foo

How to find where gem files are installed

Use gem environment to find out about your gem environment: RubyGems Environment: – RUBYGEMS VERSION: 2.1.5 – RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [x86_64-darwin12.4.0] – INSTALLATION DIRECTORY: /Users/ttm/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0 – RUBY EXECUTABLE: /Users/ttm/.rbenv/versions/2.0.0-p247/bin/ruby – EXECUTABLE DIRECTORY: /Users/ttm/.rbenv/versions/2.0.0-p247/bin – SPEC CACHE DIRECTORY: /Users/ttm/.gem/specs – RUBYGEMS PLATFORMS: – ruby – x86_64-darwin-12 – GEM PATHS: – /Users/ttm/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0 – /Users/ttm/.gem/ruby/2.0.0 … Read more

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