{"id":33992,"date":"2015-11-13T01:24:00","date_gmt":"2015-11-12T16:24:00","guid":{"rendered":"http:\/\/www.softantenna.com\/wp\/?p=33992"},"modified":"2015-11-13T01:24:01","modified_gmt":"2015-11-12T16:24:01","slug":"ruby-2-3-0-preview-1","status":"publish","type":"post","link":"https:\/\/softantenna.com\/blog\/ruby-2-3-0-preview-1\/","title":{"rendered":"\u300cRuby 2.3.0-preview1\u300d\u304c\u30ea\u30ea\u30fc\u30b9\u3001\u6587\u5b57\u5217\u30ea\u30c6\u30e9\u30eb\u306efreeze\u5316\u3078\u4e00\u6b69\u8e0f\u307f\u51fa\u3059"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/softantenna.com\/blog\/wp-content\/uploads\/2015\/11\/Iruby.jpg\" alt=\"Ruby\" title=\"ruby.jpg\" border=\"0\" width=\"545\" height=\"347\" \/><\/p>\n<p>Ruby\u958b\u767a\u30c1\u30fc\u30e0\u306f11\u670811\u65e5(\u73fe\u5730\u6642\u9593)\u3001Ruby 2.3\u7cfb\u521d\u306e\u30d7\u30ec\u30d3\u30e5\u30fc\u7248\u3068\u306a\u308b\u300cRuby 2.3.0-preview1\u300d\u3092\u30ea\u30ea\u30fc\u30b9\u3057\u307e\u3057\u305f(<a href=\"https:\/\/www.ruby-lang.org\/en\/news\/2015\/11\/11\/ruby-2-3-0-preview1-released\/\">\u516c\u5f0f\u30cb\u30e5\u30fc\u30b9<\/a>)\u3002\u73fe\u5728\u516c\u5f0f\u30b5\u30a4\u30c8\u3088\u308a\u5404\u7a2e\u5727\u7e2e\u65b9\u5f0f\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>Ruby 2.3.0-preview1\u306f\u4ee5\u4e0b\u306b\u793a\u3059\u591a\u304f\u306e\u65b0\u6a5f\u80fd\u3084\u6539\u826f\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>Frozen String Literal Pragma<\/h2>\n<p>Ruby 2.3\u3067\u306f\u3001\u6587\u5b57\u5217\u30ea\u30c6\u30e9\u30eb\u3092freeze\u3055\u308c\u305f\u3082\u306e\u3068\u3057\u3066\u51e6\u7406\u3059\u308b\u305f\u3081\u306e\u30de\u30b8\u30c3\u30af\u30b3\u30e1\u30f3\u30c8\u3068\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<pre><code class=\"ruby\"># -*- frozen_string_literal: true -*-\nstr = 'Hello '\nstr << 'World'\nputs str\n<\/code><\/pre>\n<p>\u30de\u30b8\u30c3\u30af\u30b3\u30e1\u30f3\u30c8\u300cfrozen_string_literal: true\u300d\u304c\u3042\u308b\u5834\u5408\u3001freeze\u5316\u3057\u305f\u6587\u5b57\u5217\u30ea\u30c6\u30e9\u30eb\u3068\u3057\u3066\u6271\u308f\u308c\u307e\u3059\u3002<\/p>\n<pre>\nfreeze.rb:3:in `<main>': can't modify frozen String (RuntimeError)\n<\/pre>\n<p>\u5909\u66f4\u3067\u304d\u306a\u3044\u305f\u3081\u3001\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>Safe navigation operator<\/h2>\n<p>C#\u3001Groovy\u3001Swift\u306b\u306f\u3059\u3067\u306b\u5b58\u5728\u3059\u308b\u3082\u306e\u3067\u300cobj&.foo\u300d\u3068\u3057\u3066nil\u306e\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u3092\u7c21\u5358\u5316\u3059\u308b\u3082\u306e\u3067\u3059\u3002Array#dig\u3001Hash#dig\u3082\u8ffd\u52a0\u3055\u308c\u307e\u3057\u305f\u3002<\/p>\n<pre><code class=\"ruby\">class Book\n  attr_accessor :title\nend\n\nbook = Book.new\nbook.title = 'ruby book'\nt = book\nputs \"1.\",t.title\nt = nil\nputs \"2.\",t&.title\n<\/code><\/pre>\n<p>t\u304cnil\u3067\u3082\u300ct&.title\u300d\u3060\u3068\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n<pre>\n$ ruby safe.rb\n1.\nruby book\n2.\n\n<\/pre>\n<h2>did_you_mean.gem\u306e\u6a19\u6e96\u6dfb\u4ed8<\/h2>\n<p>did_you_mean.gem\u306f\u30c7\u30d0\u30c3\u30b0\u3092\u652f\u63f4\u3057\u3001NameError\u3068NoMethodError\u306e\u5019\u88dc\u3092\u8868\u793a\u3059\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n<pre><code class=\"ruby\">require 'did_you_mean'\n\nclass User\n  attr_accessor :first_name, :last_name\n\n  def to_s\n    \"#{f1rst_name} #{last_name}\" # f1rst_name ???\n  end\nend\nuser = User.new\nuser.to_s\n<\/code><\/pre>\n<p>first_name\u3068\u66f8\u304f\u3079\u304d\u3068\u3053\u308d\u3092f1rst_name\u3068\u66f8\u3044\u305f\u6642\u3001\u6b63\u3057\u3044\u5019\u88dc\u3092\u30ea\u30b9\u30c8\u30a2\u30c3\u30d7\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<pre>\nmean.rb:7:in `to_s': undefined local variable or method `f1rst_name' for #<User:0x007fbe22006490> (NameError)\nDid you mean?  first_name\n               first_name=\n\tfrom mean.rb:11:in `<main>'\n<\/pre>\n<p>\u30c7\u30d0\u30c3\u30b0\u306b\u4fbf\u5229\u305d\u3046\u3067\u3059\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/softantenna.com\/blog\/wp-content\/uploads\/2015\/11\/Is-2015-11-13-1.17.38.png\" alt=\"S 2015 11 13 1 17 38\" title=\"s 2015-11-13 1.17.38.png\" border=\"0\" width=\"545\" height=\"264\" \/><\/p>\n<p>rbenv\u3092\u4f7f\u3063\u3066\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002Ruby 2.3\u306b\u3044\u3061\u306f\u3084\u304f\u89e6\u308c\u3066\u307f\u305f\u3044\u65b9\u306f\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u307f\u3066\u306f\u3044\u304b\u304c\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ruby\u958b\u767a\u30c1\u30fc\u30e0\u306f11\u670811\u65e5(\u73fe\u5730\u6642\u9593)\u3001Ruby 2.3\u7cfb\u521d\u306e\u30d7\u30ec\u30d3\u30e5\u30fc\u7248\u3068\u306a\u308b\u300cRuby 2.3.0-preview1\u300d\u3092\u30ea\u30ea\u30fc\u30b9\u3057\u307e\u3057\u305f(\u516c\u5f0f\u30cb\u30e5\u30fc\u30b9)\u3002\u73fe\u5728\u516c\u5f0f\u30b5\u30a4\u30c8\u3088\u308a\u5404\u7a2e\u5727\u7e2e\u65b9\u5f0f\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30c0\u30a6\u30f3\u30ed\u30fc [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":33990,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[75],"tags":[154],"class_list":["post-33992","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-ruby"],"_links":{"self":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts\/33992","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/comments?post=33992"}],"version-history":[{"count":0,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/posts\/33992\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/media\/33990"}],"wp:attachment":[{"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/media?parent=33992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/categories?post=33992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softantenna.com\/blog\/wp-json\/wp\/v2\/tags?post=33992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}