ruby

Pretty-print arrays on failure

孤街醉人 提交于 2021-01-27 08:21:22
问题 describe Rspec do it 'should print arrays in a readable manner' do arr = [ [0, :a, -1], [1, :b, -2], [2, :c, -3], [3, :d, -4], [4, :e, -5], [6, :g, -7], [7, :h, -8], [8, :i, -9] ] arr.should eql [] end end On failure: Failures: 1) Rspec should print arrays in a readable manner Failure/Error: arr.should eql [] expected: [] got: [[0, :a, -1], [1, :b, -2], [2, :c, -3], [3, :d, -4], [4, :e, -5], [6, :g, -7], [7, :h, -8], [8, :i, -9]] Is there a way to tell Rspec to pretty print its failures? My

Ruby Dir.glob mystery: Where are the FNM_xxx flags described?

白昼怎懂夜的黑 提交于 2021-01-27 07:55:22
问题 Note: This has already been posted on Ruby Forum some weeks ago. I'm crossposting it here, because I didn't get any response so far Dir.glob provides an optional parameter, usually referred as 'flags'. Where can I find a documentation about what flags are possible? The Ruby 2.0 docs just say that the flags are "the same as used in File.fnmatch". Looking up the documentation of File.fnmatch, I only find the explanation that these are the "FNM_xxx" flags, which can be or'ed together. I could

Ruby Dir.glob mystery: Where are the FNM_xxx flags described?

徘徊边缘 提交于 2021-01-27 07:52:22
问题 Note: This has already been posted on Ruby Forum some weeks ago. I'm crossposting it here, because I didn't get any response so far Dir.glob provides an optional parameter, usually referred as 'flags'. Where can I find a documentation about what flags are possible? The Ruby 2.0 docs just say that the flags are "the same as used in File.fnmatch". Looking up the documentation of File.fnmatch, I only find the explanation that these are the "FNM_xxx" flags, which can be or'ed together. I could

Array of integers into array of ranges

心已入冬 提交于 2021-01-27 07:27:06
问题 I'm trying to figure out how I can change array of integers into array of ranges. For example I want to take this array: ar = [0, 49, 14, 30, 40, 23, 59, 101] into ar = [0..49, 14..30, 40..23, 59..101] Given array always will be even. I want to take each two values as borders of ranges. I have tried to seperate it for two arrays. One with odd indexes second with even. a = ar.select.with_index{|_,i| (i+1) % 2 == 1} b = ar.select.with_index{|_,i| (i+1) % 2 == 0} I don't have an idea how to use

Array of integers into array of ranges

早过忘川 提交于 2021-01-27 07:26:05
问题 I'm trying to figure out how I can change array of integers into array of ranges. For example I want to take this array: ar = [0, 49, 14, 30, 40, 23, 59, 101] into ar = [0..49, 14..30, 40..23, 59..101] Given array always will be even. I want to take each two values as borders of ranges. I have tried to seperate it for two arrays. One with odd indexes second with even. a = ar.select.with_index{|_,i| (i+1) % 2 == 1} b = ar.select.with_index{|_,i| (i+1) % 2 == 0} I don't have an idea how to use

Issues with installing Ruby 2.0.0 on macOS Catalina

无人久伴 提交于 2021-01-27 07:16:43
问题 I'm running to issue installing Ruby 2.0.0 on a new macbook with macOS Catalina (version 10.15.7). At first I installed Ruby with rvm which did not work. I figured out that it was because Catalina's default terminal is ZSH instead of Bash (https://gorails.com/setup/osx/10.15-catalina). I was able to install Ruby 2.6.3 with the instructions but the issue is that the project I'm currently working on was written in Ruby 2.0.0. I tried installing this version with rbenv install 2.0.0-p0 but I ran

Issues with installing Ruby 2.0.0 on macOS Catalina

六眼飞鱼酱① 提交于 2021-01-27 07:15:16
问题 I'm running to issue installing Ruby 2.0.0 on a new macbook with macOS Catalina (version 10.15.7). At first I installed Ruby with rvm which did not work. I figured out that it was because Catalina's default terminal is ZSH instead of Bash (https://gorails.com/setup/osx/10.15-catalina). I was able to install Ruby 2.6.3 with the instructions but the issue is that the project I'm currently working on was written in Ruby 2.0.0. I tried installing this version with rbenv install 2.0.0-p0 but I ran

Hide ActionController::RoutingError in logs for assets

柔情痞子 提交于 2021-01-27 07:13:04
问题 I am working on a rails app that has a WP home page, and also some images that are being load from WP. On localhost we don't have access to WP content that leads to having a lot of routing errors in logs, in example: Started GET "/wp-content/uploads/2014/03/facebook-icon1.png" for 127.0.0.1 at 2015-11-20 15:10:48 +0200 ActionController::RoutingError (No route matches [GET] "/wp-content/uploads/2014/03/facebook-icon1.png"): actionpack (4.2.5) lib/action_dispatch/middleware/debug_exceptions.rb

Rails devise_token_auth gem, how do I set password reset link?

坚强是说给别人听的谎言 提交于 2021-01-27 07:06:14
问题 I have a problem for using password reset function of this gem. https://github.com/lynndylanhurley/devise_token_auth This is from the document. /password/edit GET "Verify user by password reset token. This route is the destination URL for password reset confirmation. This route must contain reset_password_token and redirect_url params. These values will be set automatically by the confirmation email that is generated by the password reset request." When users forget theirs passwords, they can

Using multiple conditions in one if-statement in Ruby Language

拥有回忆 提交于 2021-01-27 07:00:47
问题 I write something like this in Ruby: if a.max == a[0] brand = b[0] elsif a.max == a[1] brand = b[1] elsif a.max == a[2] brand = b[2] elsif a.max == a[3] brand = b[3] end a and b both are unique arrays. Is there any way to check all if and elsif 's in the same condition? Only one condition for a[0] , a[1] , a[2] and a[3] ? 回答1: Array#index might help in cases like these (assuming the size of a and b is the same): brand = b[a.index(a.max)] In cases in which the array a might be empty, you will