ruby-2.3

Installing Ruby 2.3.x on Ubuntu 18.04 is causing an error by the end of the installation process

岁酱吖の 提交于 2020-12-28 13:11:41
问题 I recently updated my system to Ubuntu 18.04 LTS, and since then, the Ruby version seems to have updated to 2.5. The issue is that, when attempting to deploy a project that uses Capistrano, it will now complain that Ruby 2.3 was not found. The version it tries to install when running rvm install 2.3 is 2.3.4, and the first error that is shown is " Error running '__rvm_make -j4' ". I tried removing RVM and installing again, but nothing solves this. The log is an enormous file which tells me

Safely assign value to nested hash using Hash#dig or Lonely operator(&.)

心已入冬 提交于 2019-12-18 12:14:39
问题 h = { data: { user: { value: "John Doe" } } } To assign value to the nested hash, we can use h[:data][:user][:value] = "Bob" However if any part in the middle is missing, it will cause error. Something like h.dig(:data, :user, :value) = "Bob" won't work, since there's no Hash#dig= available yet. To safely assign value, we can do h.dig(:data, :user)&.[]=(:value, "Bob") # or equivalently h.dig(:data, :user)&.store(:value, "Bob") But is there better way to do that? 回答1: It's not without its

IRB history not working with Ruby 2.3.0

六眼飞鱼酱① 提交于 2019-12-17 16:27:20
问题 I have Ruby 2.3.0p0 installed via rbenv, on OS X 10.11.4. Within an IRB session, history works fine. However, I cannot access IRB history across sessions. I tried my system Ruby, 2.0.0p648, and history across IRB sessions works fine. I tried installing that same version of Ruby via rbenv, and it also has working history. I've compared the values of IRB.conf between a working and nonworking session, and nothing looks out of place (although, weirdly, irb/ext/save-history.rb is a blank file in

PG::UndefinedTable: ERROR: relation “carrinho” does not exist

[亡魂溺海] 提交于 2019-12-12 04:03:47
问题 I'm using rails 4, ruby 2.3 and have a problem. How solve this error? PG::UndefinedTable: ERROR: relation "carrinho" does not exist LINE 1: SELECT "carrinho".* FROM "carrinho" WHERE "carrinho"."id" I... ^ : SELECT "carrinho".* FROM "carrinho" WHERE "carrinho"."id" IS NULL LIMIT 1 My model is carrinho.rb My controller is carrinhos_controller.rb My views is carrinhos My migration is 20160204181641_create_carrinhos.rb And in inflections have: inflect.plural "carrinhos", "carrinhos" inflect

Ruby array delete if and get deleted object

风流意气都作罢 提交于 2019-12-11 00:15:23
问题 So I have this situation where I need to delete something from an array conditionally, meaning that I want to go through the items in the array and do a test and delete the one that passes the test, and then I want to get that deleted item back. If I exclude the conditional aspect of this then Array#delete does what I want basically--returns the deleted item, but can't delete conditionally. On the other hand delete_if removes the item conditionally, but returns the remaining items back in an

What is the pre-Ruby2.3 equivalent to the safe navigation operator (`&.`)?

社会主义新天地 提交于 2019-12-10 18:40:07
问题 The answers to every question I can find (Q1, Q2) regarding Ruby's new safe navigation operator ( &. ) wrongly declare that obj&.foo is equivalent to obj && obj.foo . It's easy to demonstrate that this equivalence is incorrect: obj = false obj && obj.foo # => false obj&.foo # => NoMethodError: undefined method `foo' for false:FalseClass Further, there is the problem of multiple evaluation. Replacing obj with an expression having side effects shows that the side effects are doubled only in the

Is the current Ruby method called via super?

孤者浪人 提交于 2019-11-30 05:39:48
问题 Within a method at runtime, is there a way to know if that method has been called via super in a subclass? E.g. module SuperDetector def via_super? # what goes here? end end class Foo include SuperDetector def bar via_super? ? 'super!' : 'nothing special' end end class Fu < Foo def bar super end end Foo.new.bar # => "nothing special" Fu.new.bar # => "super!" How could I write via_super? , or, if necessary, via_super?(:bar) ? 回答1: The ultimate mix between my other, @mudasobwa's and @sawa's

What does the comment “frozen_string_literal: true” do?

﹥>﹥吖頭↗ 提交于 2019-11-28 15:32:56
This is the rspec binstub in my project directory. #!/usr/bin/env ruby begin load File.expand_path("../spring", __FILE__) rescue LoadError end # frozen_string_literal: true # # This file was generated by Bundler. # # The application 'rspec' is installed as part of a gem, and # this file is here to facilitate running it. # require "pathname" ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath) require "rubygems" require "bundler/setup" load Gem.bin_path("rspec-core", "rspec") What is this intended to do? # frozen_string_literal: true # frozen_string

IRB history not working with Ruby 2.3.0

。_饼干妹妹 提交于 2019-11-27 22:45:43
I have Ruby 2.3.0p0 installed via rbenv, on OS X 10.11.4. Within an IRB session, history works fine. However, I cannot access IRB history across sessions. I tried my system Ruby, 2.0.0p648, and history across IRB sessions works fine. I tried installing that same version of Ruby via rbenv, and it also has working history. I've compared the values of IRB.conf between a working and nonworking session, and nothing looks out of place (although, weirdly, irb/ext/save-history.rb is a blank file in both cases). Looking at my .irb_history file, it appears that it is getting replaced, rather than

In Ruby, why does nil[1]=1 evaluate to nil?

烈酒焚心 提交于 2019-11-27 16:04:40
For example: nil[1] #=> NoMethodError nil[1]=1 #=> nil It's not just syntax, as it happens with variables too: a = nil a[1] #=> NoMethodError a[1]=1 #=> nil Oddly: nil.method(:[]=) #=> NameError [].method(:[]=) #=> #<Method...> Ruby 2.3.0p0 Some random findings: [only in Ruby 2.3.0p0] The method doesn't seem to exist: nil.method(:[]=) #=> NameError: undefined method `[]=' nil.respond_to?(:[]=) #=> false And you can't invoke it using send : nil.send(:[]=) #=> NoMethodError: undefined method `[]=' Ruby evaluates neither the right hand side, nor the argument, i.e. nil[foo]=bar doesn't raise a