歡迎您光臨本站 註冊首頁

Ruby 2.7.0 preview 2 發布

←手機掃碼閱讀     admin @ 2019-10-27 , reply:0

Ruby 2.7.0 preview 2 已經發布了,最終版本計劃在 12 月發布。該版本引入了一些新特性和性能改進,主要是:

  • Compaction GC
  • Pattern Matching
  • REPL improvement
  • Separation of positional and keyword arguments

Compaction GC 

這個版本引入了 Compaction GC,以碎片化內存空間。GC.Compact 方法對堆進行壓縮,這個函數壓縮堆中的活動對象,以使用更少的頁,並且堆會更友好。

Pattern Matching(實驗性)

模式匹配是函數式程序設計語言中廣泛使用的一種特性。通過模式匹配,可以遍歷給定的對象並分配其值。


case JSON.parse('{...}', symbolize_names: true)
in {name: "Alice", children: [{name: "Bob", age: age}]}
  p age
  ...
end

REPL improvement 

irb 現在支持多行編輯,它由 reline,readline 兼容的純 Ruby 實現驅動。它還提供 rdoc 集成。在 irb 中,可以顯示給定類、模塊或方法的引用。

Separation of positional and keyword arguments

關鍵字參數和位置參數的自動轉換,將在 Ruby 3 中將刪除。

其他顯著新特點:

  • 引入編號參數作為默認塊參數
  • 添加 Enumerable#tally

["a", "b", "c", "b"].tally
#=> {"a"=>1, "b"=>2, "c"=>1}
  • 現在允許在 Self 上調用私有方法

def foo
end
private :foo
self.foo
  •  添加 Enumerator::Lazy#eager

a = %w(foo bar baz)
e = a.lazy.map {|x| x.upcase }.map {|x| x + "!" }.eager
p e.class               #=> Enumerator
p e.map {|x| x + "?" }  #=> ["FOO!?", "BAR!?", "BAZ!?"]

另外,還有更新部分標準庫:

  • Bundler 2.1.0.pre.1
  • RubyGems 3.1.0.pre.1
  • CSV 3.1.2 (NEWS)
  • Racc 1.4.15
  • REXML 3.2.3 (NEWS)
  • RSS 0.2.8 (NEWS)
  • StringScanner 1.0.3

更多詳情見發布說明。 


[admin ]

來源:OsChina
連結:https://www.oschina.net/news/110866/ruby-2-7-0-preview-2-released
Ruby 2.7.0 preview 2 發布已經有323次圍觀

http://coctec.com/news/all/show-post-217842.html