2021/04/08 今週の気になった bugs.ruby のチケット

内容は適当です。
今週と言っても今週みかけたチケットなだけでチケット自体は昔からあるやつもあります。
あくまでも『わたしが気になったチケット』で全ての bugs.ruby のチケットを載せているわけではありません。

[PR irb #219] Add pry-like show_source command

  • irb に pry のような show_source コマンドが実装された
  • これは以下のようにメソッドなどの定義を表示してくれるコマンド
$ RBENV_VERSION=3.1.0-dev irb
irb(main):001:0> require "erb"
 => true
irb(main):002:0> show_source "ERB#result"

From: /home/worker/.rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/erb.rb:901

  def result(b=new_toplevel)
    unless @_init.equal?(self.class.singleton_class)
      raise ArgumentError, "not initialized"
    end
    eval(@src, b, (@filename || '(erb)'), @lineno)
  end

 => nil
irb(main):003:0> show_source "ERB.new('<%= hello %>').src"

From: /home/worker/.rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/erb.rb:843

  attr_reader :src

 => nil
irb(main):004:0> show_source "IRB::VERSION"

From: /home/worker/.rbenv/versions/3.1.0-dev/lib/ruby/3.1.0/irb/version.rb:14

  VERSION = "1.3.5"

 => nil
irb(main):005:0>
  • どんどん irb がよくなっていって便利

[PR irb #202] process multi-line pastes as a single entity

class A
  def b; self; end
  def c; true; end
end

a = A.new

a
  .b
  # aaa
  .c

(a)
  &.b()


class A def b; self; end; def c; true; end; end;
a = A.new
a
  .b
  # aaa
  .c
(a)
  &.b()
$ irb
irb(main):001:1* class A
irb(main):002:1*   def b; self; end
irb(main):003:1*   def c; true; end
irb(main):004:0> end
 => :c
irb(main):005:0>
irb(main):006:0> a = A.new
 => #<A:0x00007fe44496c078>
irb(main):007:0>
irb(main):008:0> a
irb(main):009:0>   .b
irb(main):010:0>   # aaa
irb(main):011:0>   .c
 => true
irb(main):012:0>
irb(main):013:0> (a)
irb(main):014:0>   &.b()
 => #<A:0x00007fe44496c078>
irb(main):015:0>
irb(main):016:0>
irb(main):017:0> class A def b; self; end; def c; true; end; end;
 => :c
irb(main):018:0> a = A.new
 => #<A:0x00007fe444c7c880>
irb(main):019:0> a
irb(main):020:0>   .b
irb(main):021:0>   # aaa
irb(main):022:0>   .c
 => true
irb(main):023:0> (a)
irb(main):024:0>   &.b()
 => #<A:0x00007fe444c7c880>
irb(main):025:0>
  • こんな感じで評価できるようになって初めて irb 上でコードが実行されて次のコードがペーストされる
  • 途中のコードは途中で実行される点には注意する

[Feature #17773] Alias Numeric#zero? and Float#zero? as Numeric#empty? and Float#empty?

  • Numeric#zero?Float#zero?Numeric#empty?Float#empty?エイリアスにしようという提案
  • モチベーションとしては Web などの入力フィールドで 文字列などと同じように 0 を無効値として扱うために共通のメソッドとして #empty? がほしいという感じ
  • 0 自体は集合ではないし、 0 が意図的に入力された可能性もあるなど全体的には否定的なコメントが目立つ
  • ちなみに ActiveSupport#blank?0.blank? == false になる
  • 共有のメソッド名にするならもっと別の名前の方がよい気はするな〜

[Bug #17777] 2.6.7 fails to build on macOS: implicit declaration of function 'rb_native_mutex_destroy' is invalid in C99

  • macOSRuby 2.6.7 をビルドすると失敗するという報告
  • C99 で無効なコードを書いているのが原因ぽい?
  • ビルド前に export warnflags=-Wno-error=implicit-function-declaration をしておくことで回避することは可能
  • macOSRuby 2.6.7 をビルドする場合はご注意を