Ruby if .. elsIf .. else on a single line?
a = (foo && “a” or bar && “b” or “c”) or a = (“a” if foo) || (“b” if bar) || “c”
a = (foo && “a” or bar && “b” or “c”) or a = (“a” if foo) || (“b” if bar) || “c”
Had the same issue and everything is described here: http://railsapps.github.io/openssl-certificate-verify-failed.html tl;dr Recent versions of RVM, the Ruby Version Manager, include a utility to diagnose and resolve errors caused by outdated certificate files. See the article Installing Rails for instructions and advice. The RVM website explains how to install RVM. If you’ve installed RVM, try this: … Read more
You have several alternatives, depending on how much you want the method to be verbose and strict. # force max 2 args def foo(*args) raise ArgumentError, “Too many arguments” if args.length > 2 end # silently ignore other args def foo(*args) one, two = *args # use local vars one and two end # let … Read more
For other people on MacOS: brew cask install chromedriver And you’ll be good to go. If using Homebrew 2.6.0 (released in 2020.12.01) or above, you should use: brew install –cask chromedriver
Answer updated (twice) to reflect Rails 3+ ActiveRecord syntax Rails 3+ You can use the following syntax: Post.where(user_id: [1,2,3]) And thus: Post.where(user_id: args) Rails 3 or Rails 4 (Original) For completeness, the Rails 3 syntax would be: Post.where(“user_id IN (?)”, [1,2,3]).to_a If args is an Array, then: Post.where(“user_id IN (?)”, args).to_a Or, if args is … Read more
non capturing groups still consumes the match use “5,214”.gsub(/(\d+)(,)(\d+)/, ‘\1.\3’) or “5,214”.gsub(/(?<=\d+)(,)(?=\d+)/, ‘.’)
Use strftime: %U – Week number of the year. The week starts with Sunday. (00..53) %W – Week number of the year. The week starts with Monday. (00..53) Time.now.strftime(“%U”).to_i # 43 # Or… Date.today.strftime(“%U”).to_i # 43 If you want to add 43 weeks (or days,years,minutes, etc…) to a date, you can use 43.weeks, provided by … Read more
For Capybara, I think Tommyixi’s comment is the best: visit current_path
i fiddled around with this for quite a while and the following worked for me.. 1) install libxml2 with homebrew brew install libxml2 2) install the gem via sudo env ARCHFLAGS=”-arch x86_64″ gem install nokogiri:1.6.4.1 — –use-system-libraries –with-xml=/usr/local/Cellar/libxml2/
This works, but you should know that it’s only safe for your situation because you’re using the variables for numbers, which are immutable in Ruby. If you tried the same thing with a string, for example, you could end up with some behavior you didn’t expect: ruby-1.9.2-p180 :001 > foo = bar = “string” => … Read more