Questions tagged [ruby-2.3]

For issues relating to development in Ruby, version 2.3. If your question applies to Ruby in general, use the tag [ruby].

Ruby 2.3.0 was released on on 25 Dec 2015. It is the first stable release of the Ruby 2.3 series.

It introduces some new features (like the safe navigation operator and frozen string literals) and various performance improvements. A description of new features in Ruby 2.3 is at https://www.ruby-lang.org/en/news/2015/12/25/ruby-2-3-0-released/.

This tag is intended for questions specific to version 2.3 of Ruby.

164 questions
27
votes
3 answers

Safe navigation operator (&.) for nil

As Ruby 2.3 introduces the Safe navigation operator(&.), a.k.a lonely operator, the behavior on nil object seems odd. nil.nil? # => true nil&.nil? # => nil Is that designed to behave like this way? Or some edge case that slipped away when…
sbs
  • 4,102
  • 5
  • 40
  • 54
26
votes
7 answers

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

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,…
sbs
  • 4,102
  • 5
  • 40
  • 54
25
votes
1 answer

IRB history not working with Ruby 2.3.0

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…
Evan Pon
  • 1,496
  • 1
  • 13
  • 22
24
votes
7 answers

Segmentation fault with Rails after upgrading to OS Sierra, possibly related to sqlite3 gem

After upgrading to OSX Sierra I am having an issue with random segmentation faults. It most commonly occurs when running rails test and I believe it is due to the sqlite3_adapter. My present work around is to simply quit terminal and restart it.…
Hutch
  • 829
  • 7
  • 25
21
votes
9 answers

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

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…
user4383363
19
votes
3 answers

fix `Missing frozen string literal comment` issue

I created a new migration, it looks like this one: class AddCommentsToUsers < ActiveRecord::Migration def change add_column :users, :comments, :text end end Now with Code Climate I am warned of an issue: Missing frozen string literal…
John Smith
  • 6,105
  • 16
  • 58
  • 109
16
votes
1 answer

How do I enable the Ruby 2.3 `--enable-frozen-string-literal` globally in Rails?

I am building a greenfield Rails application on top of Ruby 2.3, and I would like all Rails commands (e.g. rails s, rails c) and all Ruby commands (e.g. rake do:something) to use the new immutable-String functionality introduced in Ruby 2.3. (See,…
aec
  • 833
  • 1
  • 9
  • 18
14
votes
3 answers

Error installing Ruby 2.3.8 in OSX 10.15.2 Catalina using RVM; OpenSSL not found

Error Error running 'env GEM_HOME=/Users/john/.rvm/gems/ruby-2.3.8@global I encountered this error while I was trying to install ruby 2.3.8 in MacOs Catalina 10.15.2 $ rvm install 2.3.8 Searching for binary rubies, this might take some time. No…
Shiva
  • 11,485
  • 2
  • 67
  • 84
9
votes
1 answer

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

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(:[]=) #=>…
larsch
  • 961
  • 8
  • 17
8
votes
2 answers

How can I describe mutable strings when strings are immutable by default?

When a file has the pragma: # frozen_string_literal: true all strings written as literals in that file are frozen by default. When I want my strings to be immutable overall, and hence am using the pragma, but want to have a couple of mutable…
sawa
  • 165,429
  • 45
  • 277
  • 381
5
votes
1 answer

Ruby 2.3.8 installation error using rbenv in mint | uncommon.mk:203: recipe for target 'build-ext' failed

I have freshly installed Mint 19(Tara) and was trying to install Ruby 2.3.8 using rbenv and got this error.Can anyone help me with this? $ rbenv install 2.3.8 …
Shiva
  • 11,485
  • 2
  • 67
  • 84
5
votes
3 answers

Order Hash and delete first key-value pair

I have a Hash with timestamp as keys. hash = { "2016-05-31T22:30:58+02:00" => { "path" => "/", "method" => "GET" }, "2016-05-31T22:31:23+02:00" => { "path" => "/tour", "method" => "GET" }, …
Fellow Stranger
  • 32,129
  • 35
  • 168
  • 232
5
votes
1 answer

Ruby not releasing memory

I have Ruby code that more or less look like this offset = 0 index = 1 User.establish_connection(..) # db1 class Member < ActiveRecord::Base self.table_name = 'users' end Member.establish_connection(..) #db2 while true users =…
Viren
  • 5,812
  • 6
  • 45
  • 98
5
votes
5 answers

Is the current Ruby method called via super?

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? ?…
Mori
  • 27,279
  • 10
  • 68
  • 73
4
votes
1 answer

Ruby syntax error when try to puts literal hash

Could someone explain to me why in ruby console (version 2.3.4) trying to print hashes these work: puts({a: 'a', b: 'b'}) puts(a: 'a', b: 'b') puts a: 'a', b: 'b' puts [a: 'a', b: 'b'] <<< array length 1 with value of hash puts Hash[a: 'a', b:…
mhively
  • 93
  • 6
1
2 3
10 11