{"id":222941,"date":"2014-05-16T19:55:03","date_gmt":"2014-05-16T15:55:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=222941"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=222941","title":{"rendered":"<span class=\"post_title\">Ruby 2.1 \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445 (\u0427\u0430\u0441\u0442\u044c 1)<\/span>"},"content":{"rendered":"<div class=\"content html_format\">       <img decoding=\"async\" align=\"right\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/ccd\/b8f\/bab\/ccdb8fbabd2b13bae6145fa4da9c7ac2.png\"\/><br \/>  Ruby 2.1, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0437\u043d\u0430\u0447\u0438\u043c\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f Ruby (\u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430), \u0431\u044b\u043b\u0430 \u0432\u044b\u043f\u0443\u0449\u0435\u043d\u0430 \u0432 \u0420\u043e\u0436\u0434\u0435\u0441\u0442\u0432\u043e 2013, \u0441\u043f\u0443\u0441\u0442\u044f \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c 10 \u043c\u0435\u0441\u044f\u0446\u0435\u0432 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 2.0.0. \u041e\u043d\u0430 \u0432\u044b\u0448\u043b\u0430 \u0441 \u0446\u0435\u043b\u044b\u043c \u0440\u044f\u0434\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439, \u0438 \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0441\u0442 \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u044d\u0442\u0438 \u043d\u043e\u0432\u0448\u0435\u0441\u0442\u0432\u0430.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h5>\u041d\u043e\u0432\u0430\u044f \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u0441\u0438\u044f\u043c\u0438<\/h5>\n<p>  \u0421 \u0432\u0435\u0440\u0441\u0438\u0435\u0439 2.1 Ruby \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u043d\u043e\u0432\u0443\u044e \u0441\u0445\u0435\u043c\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u0435\u0440\u0441\u0438\u0439 \u043d\u0430 \u0431\u0430\u0437\u0435 <a href=\"http:\/\/semver.org\/\">Semantic Versioning<\/a>.<\/p>\n<p>  \u0412\u0435\u0440\u0441\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u044f\u0442 \u043f\u043e \u0441\u0445\u0435\u043c\u0435 MAJOR.MINOR.TEENY, \u0442.\u0435. \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 2.1.0: 2 \u2014 \u043c\u0430\u0436\u043e\u0440\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f, 1 \u2014 \u043c\u0438\u043d\u043e\u0440\u043d\u0430\u044f, \u043c\u043b\u0430\u0434\u0448\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u2014 0. \u041d\u043e\u043c\u0435\u0440 \u043c\u043b\u0430\u0434\u0448\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u0438\u0437 \u043f\u0430\u0442\u0447\u043b\u0435\u0432\u0435\u043b\u0430 \u0434\u043b\u044f \u043c\u0438\u043d\u043e\u0440\u043d\u043e\u0433\u043e \u0431\u0430\u0433\u0430 \u0438 \u0443\u044f\u0437\u0432\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u041d\u043e\u043c\u0435\u0440 \u043c\u0438\u043d\u043e\u0440\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043d\u043e\u0432\u044b\u0445 \u0444\u0438\u0447, \u043f\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0445, \u0430 \u043c\u0430\u0436\u043e\u0440\u043d\u043e\u0439 \u2014 \u0434\u043b\u044f \u043d\u0435\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u043f\u0443\u0449\u0435\u043d\u044b \u043f\u043e\u0434 \u043c\u0438\u043d\u043e\u0440\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0435\u0439.<\/p>\n<p>  \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 1.9.3 \u0438 1.9.3-p545 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u0435\u043b\u0438\u0437\u044b \u0432\u0438\u0434\u0430 2.1 \u0438 2.1.1.<\/p>\n<p>  \u041f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u044b\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043c\u0438\u043d\u043e\u0440\u043d\u044b\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 \u043a\u0430\u0436\u0434\u044b\u0435 12 \u043c\u0435\u0441\u044f\u0446\u0435\u0432, \u0442.\u0435. \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0436\u0438\u0434\u0430\u0442\u044c Ruby 2.2 \u043a \u0420\u043e\u0436\u0434\u0435\u0441\u0442\u0432\u0443 2014.<\/p>\n<h5>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b<\/h5>\n<p>  \u0412 <a href=\"http:\/\/globaldev.co.uk\/2013\/03\/ruby-2-0-0-in-detail\/#keyword_arguments\">\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b<\/a>, \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0435\u0441\u044f \u0432 Ruby 2.0.0 \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u043b\u044f \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043f\u0440\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430, \u0438 \u0435\u0441\u043b\u0438 \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u043e\u043d\u0438 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0434\u0430\u043d\u044b, \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0431\u0443\u0436\u0434\u0435\u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0430.<\/p>\n<pre><code class=\"ruby\"># length is required def pad(num, length:, char: &quot;0&quot;)   num.to_s.rjust(length, char) end  pad(42, length: 6)   #=&gt; &quot;000042&quot; pad(42)              #=&gt; #&lt;ArgumentError: missing keyword: length&gt; <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435, \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0434\u043b\u044f \u0443\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e\u0441\u0442\u0438, \u043d\u043e \u0434\u043b\u044f \u043d\u0438\u0445 \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c.<\/p>\n<h5>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 String#freeze<\/h5>\n<p>  \u0422.\u043a. \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 Ruby \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c\u0438, \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0439 \u043b\u0438\u0442\u0435\u0440\u0430\u043b \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u0432\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438:<\/p>\n<pre><code class=\"ruby\">def env   &quot;development&quot; end  # returns new String object on each call env.object_id   #=&gt; 70329318373020 env.object_id   #=&gt; 70329318372900 <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u0435\u0441\u044c\u043c\u0430 \u0440\u0430\u0441\u0442\u043e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u2014 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0430 \u0437\u0430\u0442\u0435\u043c \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0438\u0445 \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u043e\u043c \u043c\u0443\u0441\u043e\u0440\u0430. \u0427\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u044d\u0442\u043e\u0433\u043e, \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 #freeze, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u0438\u0441\u043a \u0441\u0442\u0440\u043e\u043a\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u00ab\u0437\u0430\u043c\u043e\u0440\u043e\u0436\u0435\u043d\u043d\u044b\u0445\u00bb \u0441\u0442\u0440\u043e\u043a, \u0438 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437:<\/p>\n<pre><code class=\"ruby\">def env   &quot;development&quot;.freeze end  # returns the same String object on each call env.object_id   #=&gt; 70365553080120 env.object_id   #=&gt; 70365553080120 <\/code><\/pre>\n<p>  \u0421\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0435 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b, \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0445\u044d\u0448\u0430, \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0430\u0442\u044c\u0441\u044f \u0442\u0430\u043a \u0436\u0435 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u044b\u0437\u043e\u0432\u0430 #freeze.<\/p>\n<pre><code class=\"ruby\">a = {&quot;name&quot; =&gt; &quot;Arthur&quot;} b = {&quot;name&quot; =&gt; &quot;Ford&quot;}  # same String object used as key in both hashes a.keys.first.object_id   #=&gt; 70253124073040 b.keys.first.object_id   #=&gt; 70253124073040 <\/code><\/pre>\n<p>  \u0412 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 2.1 \u044d\u0442\u0430 \u0444\u0438\u0447\u0430 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u044b\u043b\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435\u043c \u0432 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0435, \u0433\u0434\u0435 \u00abstring\u00bbf \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u043b\u043e \u00ab\u0437\u0430\u043c\u043e\u0440\u043e\u0436\u0435\u043d\u043d\u0443\u044e\u00bb \u0441\u0442\u0440\u043e\u043a\u0443. \u041e\u0434\u043d\u0430\u043a\u043e \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043e\u0442 \u0442\u0430\u043a\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043a \u0432\u044b\u0437\u043e\u0432\u0443 \u043c\u0435\u0442\u043e\u0434\u0430 #freeze, \u0447\u0442\u043e \u043d\u0435 \u043b\u043e\u043c\u0430\u0435\u0442 \u043f\u0440\u044f\u043c\u0443\u044e \u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c, \u043f\u043b\u044e\u0441 \u043a \u0442\u043e\u043c\u0443 \u043c\u043d\u043e\u0433\u0438\u0435 \u043b\u044e\u0434\u0438 \u043d\u0435\u0434\u043e\u043b\u044e\u0431\u043b\u0438\u0432\u0430\u044e\u0442 \u043b\u0438\u0448\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u0435.<\/p>\n<h5>def \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 Symbol<\/h5>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 nil, \u0430 \u043e\u0431\u044a\u0435\u043a\u0442 Symbol, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0438\u043c\u0435\u043d\u0438 \u043c\u0435\u0442\u043e\u0434\u0430. \u041a\u0430\u043d\u043e\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<pre><code class=\"ruby\">class Client   def initialize(host, port)     # ...   end    private def do_request(method, path, body, **headers)     # ...   end    def get(path, **headers)     do_request(:get, path, nil, **headers)   end end <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0435\u043a\u043e\u0440\u0430\u0442\u043e\u0440\u043e\u0432 \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c, \u043d\u0438\u0436\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <a href=\"http:\/\/globaldev.co.uk\/2013\/03\/ruby-2-0-0-in-detail\/#id4\">Module#prepend<\/a> \u0434\u043b\u044f \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 before\/after \u043a\u043e\u043b\u043b\u0431\u044d\u043a\u0438:<\/p>\n<pre><code class=\"ruby\">module Around   def around(method)     prepend(Module.new do       define_method(method) do |*args, &block|         send(:&quot;before_#{method}&quot;) if respond_to?(:&quot;before_#{method}&quot;, true)         result = super(*args, &block)         send(:&quot;after_#{method}&quot;) if respond_to?(:&quot;after_#{method}&quot;, true)         result       end     end)     method   end end  class Example   extend Around    around def call     puts &quot;call&quot;   end    def before_call     puts &quot;before&quot;   end    def after_call     puts &quot;after&quot;   end end  Example.new.call <\/code><\/pre>\n<p>  \u0432\u044b\u0432\u0435\u0434\u0435\u0442<\/p>\n<pre><code class=\"ruby\">before call after <\/code><\/pre>\n<p>  \u041c\u0435\u0442\u043e\u0434\u044b define_method \u0438 define_singleton_method \u0442\u0430\u043a\u0436\u0435 \u0431\u044b\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Symbol \u0432\u043c\u0435\u0441\u0442\u043e \u0438\u0445 proc-\u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<h5>\u041b\u0438\u0442\u0435\u0440\u0430\u043b\u044b \u0434\u043b\u044f \u0440\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0438 \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b<\/h5>\n<p>  \u0412 Ruby \u0435\u0441\u0442\u044c \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432 Integer(1) \u0438 Float(1.0), \u0442\u0435\u043f\u0435\u0440\u044c \u043a \u043d\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432 Rational(1r) \u0438 Complex(1i).<\/p>\n<p>  \u041e\u043d\u0438 \u0445\u043e\u0440\u043e\u0448\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432 Ruby, \u0442\u0430\u043a \u0447\u0442\u043e 1\/3 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u0432 Ruby \u043a\u0430\u043a 1\/3r. 3i \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e 0+3i, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u043d\u043e\u0442\u0430\u0446\u0438\u0438, 2+3i \u0432 Ruby \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043a\u043e\u043c\u043f\u043b\u0435\u043a\u0441\u043d\u043e\u0435 \u0447\u0438\u0441\u043b\u043e 2+3i!<\/p>\n<h5>Array\/Enumerable #to_h<\/h5>\n<p>  \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0445 \u043c\u0435\u0442\u043e\u0434 <a href=\"http:\/\/globaldev.co.uk\/2013\/03\/ruby-2-0-0-in-detail\/#_as_standard_for_convert_to_hash\">#to_h<\/a> \u0432 Ruby 2.0.0 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u043e\u043b\u043d\u0438\u043b\u043e\u0441\u044c \u043a\u043b\u0430\u0441\u0441\u043e\u043c Array \u0438 \u043b\u044e\u0431\u044b\u043c \u0434\u0440\u0443\u0433\u0438\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u043c Enumerable.<\/p>\n<pre><code class=\"ruby\">[[:id, 42], [:name, &quot;Arthur&quot;]].to_h      #=&gt; {:id=&gt;42, :name=&gt;&quot;Arthur&quot;}  require &quot;set&quot; Set[[:id, 42], [:name, &quot;Arthur&quot;]].to_h   #=&gt; {:id=&gt;42, :name=&gt;&quot;Arthur&quot;} <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 Hash, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0445 Array:<\/p>\n<pre><code class=\"ruby\">headers = {&quot;Content-Length&quot; =&gt; 42, &quot;Content-Type&quot; =&gt; &quot;text\/html&quot;} headers.map {|k, v| [k.downcase, v]}.to_h #=&gt; {&quot;content-length&quot; =&gt; 42, &quot;content-type&quot; =&gt; &quot;text\/html&quot;} <\/code><\/pre>\n<h5>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432<\/h5>\n<p>  \u0414\u043e \u0432\u0435\u0440\u0441\u0438\u0438 2.1 Ruby \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u044d\u0448 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043d\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u043b\u0441\u044f \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043f\u0440\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u044f, \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u044f \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u0442.\u0434. \u0432 \u043b\u044e\u0431\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0432\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430. \u042d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b (\u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a OpenStruct) \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u0435\u043c\u044b(\u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a <a href=\"http:\/\/globaldev.co.uk\/2013\/09\/ruby-tips-part-3\/#exceptions\">\u0442\u044d\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439<\/a>) \u0431\u0435\u0441\u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c\u0438 \u0432\u0432\u0438\u0434\u0443 \u0441\u043e\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, Ruby 2.1 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u0431\u0430\u0437\u0438\u0440\u0443\u044e\u0449\u0435\u0435\u0441\u044f \u043d\u0430 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0438\u043d\u0432\u0430\u043b\u0438\u0434\u0438\u0440\u0443\u044f \u043a\u044d\u0448 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u0435\u0433\u043e \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441 RubyVM \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u043a\u044d\u0448\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432:<\/p>\n<pre><code class=\"ruby\">class Foo end  RubyVM.stat   #=&gt; {:global_method_state=&gt;133, :global_constant_state=&gt;820, :class_serial=&gt;5689}  # setting constant increments :global_constant_state  Foo::Bar = &quot;bar&quot;  RubyVM.stat(:global_constant_state)   #=&gt; 821  # defining instance method increments :class_serial  class Foo   def foo   end end  RubyVM.stat(:class_serial)            #=&gt; 5690  # defining global method increments :global_method_state  def foo end  RubyVM.stat(:global_method_state)     #=&gt; 134 <\/code><\/pre>\n<h5>\u0418\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f<\/h5>\n<p>  \u0423 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0442\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 #cause, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u0432\u043e\u0437\u0431\u0443\u0434\u0438\u0432\u0448\u0435\u0435 \u0434\u0430\u043d\u043d\u043e\u0435. \u041e\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442\u0435 \u043e\u0434\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u0432\u043e\u0437\u0431\u0443\u0436\u0434\u0430\u0435\u0442\u0435 \u0434\u0440\u0443\u0433\u043e\u0435.<\/p>\n<pre><code class=\"ruby\">require &quot;socket&quot;  module MyProject   Error = Class.new(StandardError)   NotFoundError = Class.new(Error)   ConnectionError = Class.new(Error)    def self.get(path)     response = do_get(path)     raise NotFoundError, &quot;#{path} not found&quot; if response.code == &quot;404&quot;     response.body   rescue Errno::ECONNREFUSED, SocketError =&gt; e     raise ConnectionError   end end  begin   MyProject.get(&quot;\/example&quot;) rescue MyProject::Error =&gt; e   e         #=&gt; #&lt;MyProject::ConnectionError: MyProject::ConnectionError&gt;   e.cause   #=&gt; #&lt;Errno::ECONNREFUSED: Connection refused - connect(2) for &quot;example.com&quot; port 80&gt; end <\/code><\/pre>\n<p>  \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043f\u0435\u0440\u0432\u043e\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0438 rescue \u043d\u0435 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043f\u0440\u0438\u0447\u0438\u043d\u0443 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u043e\u0432\u0435\u043d\u0438\u044f, \u043d\u043e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 #cause \u043c\u043e\u0436\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043f\u043e\u043c\u043e\u0447\u044c \u043f\u0440\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0435. <\/p>\n<p>  \u0423 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043c\u0435\u0442\u043e\u0434 #backtrace_locations, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 <a href=\"http:\/\/globaldev.co.uk\/2013\/03\/ruby-2-0-0-in-detail\/#optimised_backtrace\">\u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 2.0.0<\/a>. \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u044b Thread::Backtrace::Location \u0432\u043c\u0435\u0441\u0442\u043e \u0441\u0442\u0440\u043e\u043a, \u0447\u0442\u043e \u0434\u0430\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0435\u0442\u0430\u043b\u044f\u043c \u0431\u044d\u043a\u0442\u0440\u0435\u0439\u0441\u0430.<\/p>\n<h5>\u041f\u043e\u043a\u043e\u043b\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0443\u0441\u043e\u0440\u0430<\/h5>\n<p>  \u0412 Ruby 2.1 \u0432\u0432\u0435\u0434\u0435\u043d \u0441\u0431\u043e\u0440\u0449\u0438\u043a \u043c\u0443\u0441\u043e\u0440\u0430 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442 \u0432\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043d\u0430 \u043c\u043b\u0430\u0434\u0448\u0435\u0435 \u0438 \u0441\u0442\u0430\u0440\u0448\u0435\u0435 \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f. \u041f\u0440\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435 GC \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043b\u0430\u0434\u0448\u0435\u0433\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f, \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0436\u0435 \u0441\u0442\u0430\u0440\u0448\u0435\u0433\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0435\u0436\u0435. \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (sweeping) \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e \u0442\u043e\u0439 \u0436\u0435 \u0441\u0445\u0435\u043c\u0435, \u0447\u0442\u043e \u0438 \u0432 1.9.3(lazy sweep). \u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 \u043c\u043b\u0430\u0434\u0448\u0435\u0433\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f \u201c\u0432\u044b\u0436\u0438\u0432\u0430\u0435\u0442\u201d \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 GC, \u043e\u043d \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u0442\u0430\u0440\u0448\u0435\u0435 \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u0442\u0430\u0440\u0448\u0435\u0433\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f, \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043b\u0430\u0434\u0448\u0435\u0433\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f, \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043b\u0430\u0434\u0448\u0435\u0433\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f GC \u043c\u043e\u0436\u0435\u0442 \u043e\u0448\u0438\u0431\u043e\u0447\u043d\u043e \u043f\u043e\u0441\u0447\u0438\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0435\u0442 \u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0435\u0433\u043e. \u0414\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u044b\u043b\u0438 \u0432\u0432\u0435\u0434\u0435\u043d\u044b \u0431\u0430\u0440\u044c\u0435\u0440\u044b \u0437\u0430\u043f\u0438\u0441\u0438, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u0442\u0430\u0440\u0448\u0435\u0433\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f \u0432 \u043e\u0441\u043e\u0431\u043e\u0435 \u0437\u0430\u043f\u043e\u043c\u0438\u043d\u0430\u0435\u043c\u043e\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e (remember set), \u043a\u043e\u0433\u0434\u0430 \u043e\u043d\u0438 \u043f\u0440\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043c\u043b\u0430\u0434\u0448\u0435\u0433\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 old_array.push(young_string)). \u042d\u0442\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u0442\u0435\u043c \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043c\u0430\u0440\u043a\u0438\u0440\u043e\u0432\u043a\u0435 (marking) \u043c\u043b\u0430\u0434\u0448\u0435\u0433\u043e \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0443 \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0447\u0435\u0441\u043a\u0438\u0445 \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u043e\u0432 \u043c\u0443\u0441\u043e\u0440\u0430 \u0442\u0430\u043a\u0438\u0435 \u0431\u0430\u0440\u044c\u0435\u0440\u044b \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u043e \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 C-\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439 \u0434\u043b\u044f Ruby \u044d\u0442\u043e \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0431\u044b\u043b\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043e, \u0447\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u044b \u0431\u0430\u0440\u044c\u0435\u0440\u044b (\u0442.\u043d. \u201c\u0442\u0435\u043d\u0435\u0432\u044b\u0435\u201d \u043e\u0431\u044a\u0435\u043a\u0442\u044b) \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u0441\u0442\u0430\u0440\u0448\u0435\u0435 \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u0435. \u042d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0435\u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u0432 \u043f\u043b\u0430\u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0430 \u043c\u0443\u0441\u043e\u0440\u0430, \u043d\u043e \u0437\u0430\u0442\u043e \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043e\u0431\u0440\u0430\u0442\u043d\u0443\u044e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0444\u0430\u0437\u0430 \u043c\u0430\u0440\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u043d\u043e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0431\u0430\u0440\u044c\u0435\u0440\u043e\u0432 \u0437\u0430\u043f\u0438\u0441\u0438 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u043a\u043b\u0430\u0434\u043d\u044b\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u044b, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0442\u043b\u0438\u0447\u0438\u044f \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0437\u0430\u0432\u0438\u0441\u044f\u0442 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u0430\u0448 \u043a\u043e\u0434.<\/p>\n<h5>\u041a\u043b\u0430\u0441\u0441 GC<\/h5>\n<p>  \u041c\u0435\u0442\u043e\u0434 GC.start \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0432\u0430 \u043d\u043e\u0432\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430, full_mark \u0438 immediate_sweep. \u041e\u0431\u0430 \u043f\u043e \u0443\u043c\u043e\u0447\u0430\u043d\u0438\u044e true.<br \/>  \u0415\u0441\u043b\u0438 full_mark \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0432 true, \u0444\u0430\u0437\u0430 \u043c\u0430\u0440\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u043e\u0431\u043e\u0438\u0445 \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u0439, \u0435\u0441\u043b\u0438 \u0432 false, \u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043c\u043b\u0430\u0434\u0448\u0435\u0433\u043e. \u0415\u0441\u043b\u0438 immediate_sweep \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0432 true, \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043e \u043f\u043e\u043b\u043d\u043e\u0435 \u043d\u0435\u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e\u0435 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (stop the world), \u0435\u0441\u043b\u0438 \u0432 false, \u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u043e \u201c\u043b\u0435\u043d\u0438\u0432\u043e\u0435\u201d \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 (lazy sweep), \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0433\u0434\u0430 \u044d\u0442\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438 \u0443\u0434\u0430\u043b\u044f\u044e\u0449\u0435\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<pre><code class=\"ruby\">GC.start # trigger a full GC run GC.start(full_mark: false) # only collect young generation GC.start(immediate_sweep: false) # mark only GC.start(full_mark: false, immediate_sweep: false) # minor GC <\/code><\/pre>\n<p>  \u041e\u043f\u0446\u0438\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438 GC.stress \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u043a\u0430\u043a \u0446\u0435\u043b\u043e\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0439 \u0444\u043b\u0430\u0433, \u0437\u0430\u0434\u0430\u044e\u0449\u0438\u0439, \u043a\u0430\u043a\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0443\u0441\u0438\u043b\u0435\u043d\u0430.<\/p>\n<pre><code class=\"ruby\">GC.stress = true # full GC at every opportunity GC.stress = 1    # minor marking at every opportunity GC.stress = 2    # lazy sweep at every opportunity <\/code><\/pre>\n<p>  GC.stat \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0435\u0442\u0430\u043b\u0435\u0439, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u0445\u043e\u0434 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430, \u0432\u043c\u0435\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0430 \u0432\u0441\u0435\u0433\u043e \u0445\u044d\u0448\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439.<\/p>\n<pre><code class=\"ruby\">GC.stat                    #=&gt; {:count=&gt;6, ... } GC.stat(:major_gc_count)   #=&gt; 2 GC.stat(:minor_gc_count)   #=&gt; 4 <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043c\u0435\u0442\u043e\u0434 latest_gc_info, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0430 \u043c\u0443\u0441\u043e\u0440\u0430.<\/p>\n<pre><code class=\"ruby\">GC.latest_gc_info   #=&gt; {:major_by=&gt;:oldgen, :gc_by=&gt;:newobj, :have_finalizer=&gt;false, :immediate_sweep=&gt;false} <\/code><\/pre>\n<h5>GC \u2014 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f<\/h5>\n<p>  \u0411\u044b\u043b\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u043e \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043d\u043e\u0432\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0430 \u043c\u0443\u0441\u043e\u0440\u0430 \u0432 Ruby.<\/p>\n<h6>RUBY_GC_HEAP_INIT_SLOTS<\/h6>\n<p>\u042d\u0442\u0430 \u043e\u043f\u0446\u0438\u044f \u0431\u044b\u043b\u0430 \u0440\u0430\u043d\u0435\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043a\u0430\u043a RUBY_HEAP_MIN_SLOTS. \u041e\u043d\u0430 \u0437\u0430\u0434\u0430\u0435\u0442 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441\u043b\u043e\u0442\u043e\u0432 \u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0432 10000.<\/p>\n<h6>RUBY_GC_HEAP_FREE_SLOTS<\/h6>\n<p>\u042d\u0442\u0430 \u043e\u043f\u0446\u0438\u044f \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u043d\u0435\u0435 \u0431\u044b\u043b\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043a\u0430\u043a RUBY_FREE_MIN. \u041e\u043d\u0430 \u0437\u0430\u0434\u0430\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 GC. \u0415\u0441\u043b\u0438 GC \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u043b \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0442\u043e\u0432, \u0431\u0443\u0434\u0443\u0442 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u044b \u043d\u043e\u0432\u044b\u0435.\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u2014 4096.<\/p>\n<h6>RUBY_GC_HEAP_GROWTH_FACTOR<\/h6>\n<p>\u0417\u0430\u0434\u0430\u0435\u0442 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0442\u0438 \u0447\u0438\u0441\u043b\u043e \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0445 \u0441\u043b\u043e\u0442\u043e\u0432. (next slots number) = (current slots number) * (this factor). \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u2014 1.8.<\/p>\n<h6>RUBY_GC_HEAP_GROWTH_MAX_SLOTS<\/h6>\n<p>\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u043b\u043e\u0442\u043e\u0432, \u0432\u044b\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0445 \u0437\u0430 \u043e\u0434\u0438\u043d \u0440\u0430\u0437. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 0, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u043d\u0435 \u0437\u0430\u0434\u0430\u043d.<\/p>\n<h6>RUBY_GC_MALLOC_LIMIT<\/h6>\n<p>\u042d\u0442\u0430 \u043e\u043f\u0446\u0438\u044f \u043d\u0435 \u043d\u043e\u0432\u0430\u044f, \u043d\u043e \u0437\u0430\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u0435\u0442 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u044f. \u041e\u043d\u0430 \u0437\u0430\u0434\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u044b\u0434\u0435\u043b\u0435\u043d \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0441\u0431\u043e\u0440\u043a\u0435 \u043c\u0443\u0441\u043e\u0440\u0430.\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 16 * 1024 * 1024 (16MB).<\/p>\n<h6>RUBY_GC_MALLOC_LIMIT_GROWTH_FACTOR<\/h6>\n<p>\u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f malloc_limit, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1.4.<\/p>\n<h6>RUBY_GC_MALLOC_LIMIT_MAX<\/h6>\n<p>\u041c\u0430\u043a\u0441\u0438\u043c\u0443\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0447\u044c malloc_limit. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 32 * 1024 * 1024 (32MB).<\/p>\n<h6>RUBY_GC_OLDMALLOC_LIMIT<\/h6>\n<p>\u041e\u0431\u044a\u0435\u043c, \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0447\u044c \u0441\u0442\u0430\u0440\u0448\u0435\u0435 \u043f\u043e\u043a\u043e\u043b\u0435\u043d\u0438\u0435 \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u043f\u043e\u043b\u043d\u043e\u0439 \u0441\u0431\u043e\u0440\u043a\u0438 \u043c\u0443\u0441\u043e\u0440\u0430. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 16 * 1024 * 1024 (16MB).<\/p>\n<h6>RUBY_GC_OLDMALLOC_LIMIT_GROWTH_FACTOR<\/h6>\n<p>\u041a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f old_malloc_limit. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1.2.<\/p>\n<h6>RUBY_GC_OLDMALLOC_LIMIT_MAX<\/h6>\n<p>\u041c\u0430\u043a\u0441\u0438\u043c\u0443\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0447\u044c old_malloc_limit. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 128 * 1024 * 1024 (128MB).<\/p>\n<h5>\u041a\u043b\u0430\u0441\u0441 ObjectSpace \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0443\u0442\u0435\u0447\u0435\u043a \u043f\u0430\u043c\u044f\u0442\u0438<\/h5>\n<p>  Ruby 2.1 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0441\u0442\u0430\u0440\u044b\u0435\/\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u043d\u0435 \u0434\u0430\u0432\u0430\u044f \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043a \u043d\u0438\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0443 \u043c\u0443\u0441\u043e\u0440\u0430.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"ruby\">require &quot;objspace&quot;  module Example   class User     def initialize(first_name, last_name)       @first_name, @last_name = first_name, last_name     end      def name       &quot;#{@first_name} #{@last_name}&quot;     end   end end  ObjectSpace.trace_object_allocations do   obj = Example::User.new(&quot;Arthur&quot;, &quot;Dent&quot;).name   ObjectSpace.allocation_sourcefile(obj)   #=&gt; &quot;example.rb&quot;   ObjectSpace.allocation_sourceline(obj)   #=&gt; 10   ObjectSpace.allocation_class_path(obj)   #=&gt; &quot;Example::User&quot;   ObjectSpace.allocation_method_id(obj)    #=&gt; :name   ObjectSpace.allocation_generation(obj)   #=&gt; 6 end <\/code><\/pre>\n<p>  \u0427\u0438\u0441\u043b\u043e, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u043c allocation_generation, \u044d\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0431\u043e\u0440\u043e\u043a \u043c\u0443\u0441\u043e\u0440\u0430, \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0445 \u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0422.\u043e., \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0447\u0438\u0441\u043b\u043e \u043c\u0430\u043b\u043e, \u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b trace_object_allocations_start \u0438 trace_object_allocations_stop \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e trace_object_allocations \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435\u0439 \u0431\u043b\u043e\u043a\u0430, \u0438 \u043c\u0435\u0442\u043e\u0434 trace_object_allocations_clear \u0434\u043b\u044f \u0441\u0431\u0440\u043e\u0441\u0430 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043c\u043e\u0436\u043d\u043e \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u044d\u0442\u0443 \u0438 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0444\u0430\u0439\u043b \u0438\u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 JSON \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0438\u043b\u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<pre><code class=\"ruby\">require &quot;objspace&quot;  ObjectSpace.trace_object_allocations do   puts ObjectSpace.dump([&quot;foo&quot;].freeze) end <\/code><\/pre>\n<p>  \u0432\u044b\u0432\u0435\u0434\u0435\u0442  <\/p>\n<pre><code class=\"ruby\">{     &quot;address&quot;: &quot;0x007fd122123f40&quot;,     &quot;class&quot;: &quot;0x007fd121072098&quot;,     &quot;embedded&quot;: true,     &quot;file&quot;: &quot;example.rb&quot;,     &quot;flags&quot;: {         &quot;wb_protected&quot;: true     },     &quot;frozen&quot;: true,     &quot;generation&quot;: 6,     &quot;length&quot;: 1,     &quot;line&quot;: 4,     &quot;references&quot;: [         &quot;0x007fd122123f68&quot;     ],     &quot;type&quot;: &quot;ARRAY&quot; } <\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 ObjectSpace.dump_all \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e\u0431\u043e \u0432\u0441\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u0443\u0447\u0435.<\/p>\n<pre><code class=\"ruby\">require &quot;objspace&quot; ObjectSpace.trace_object_allocations_start # do things ... ObjectSpace.dump_all(output: File.open(&quot;heap.json&quot;, &quot;w&quot;)) <\/code><\/pre>\n<p>  \u041e\u0431\u0430 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0431\u0435\u0437 \u0430\u043a\u0442\u0438\u0432\u0430\u0446\u0438\u0438 object allocation tracing, \u043d\u043e \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u043c\u0435\u043d\u044c\u0448\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 ObjectSpace.reachable_objects_from_root, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u043c\u0435\u0442\u043e\u0434\u0443 ObjectSpace.reachable_objects_from, \u043d\u043e \u043e\u043d \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442 \u043a\u043e\u0440\u043d\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0423 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0435\u0441\u0442\u044c \u043e\u0434\u043d\u0430 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u2014 \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0445\u044d\u0448, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0430\u043c \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0438\u0445 \u043d\u0430 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u044c, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0442\u0435 \u0436\u0435 \u0441\u0442\u0440\u043e\u043a\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0435 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441 \u0442\u0435\u043c \u0436\u0435 object_id, \u0447\u0442\u043e \u0438 \u0432 \u0441\u0430\u043c\u043e\u043c \u0445\u044d\u0448\u0435. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e \u044d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438:<\/p>\n<pre><code class=\"ruby\">require &quot;objspace&quot;  reachable = ObjectSpace.reachable_objects_from_root reachable = {}.merge(reachable) # workaround compare_by_identity reachable[&quot;symbols&quot;]   #=&gt; [&quot;freeze&quot;, &quot;inspect&quot;, &quot;intern&quot;, ... <\/code><\/pre>\n<p>  <i>\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u043c \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0430, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u0440\u0443 \u0434\u043d\u0435\u0439, \u0432 \u043d\u0435\u0439 \u0431\u0443\u0434\u0443\u0442 refinements, \u043d\u043e\u0432\u044b\u0435 rubygems, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043b\u044f\u043c\u0431\u0434\u0430\u0445 \u0438 \u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e \u0432\u0441\u0435\u0433\u043e.<br \/>  <\/i>   \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/222941\/\"> http:\/\/habrahabr.ru\/post\/222941\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">       <img decoding=\"async\" align=\"right\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/ccd\/b8f\/bab\/ccdb8fbabd2b13bae6145fa4da9c7ac2.png\"\/><br \/>  Ruby 2.1, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0437\u043d\u0430\u0447\u0438\u043c\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f Ruby (\u043d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043f\u043e\u0441\u0442\u0430), \u0431\u044b\u043b\u0430 \u0432\u044b\u043f\u0443\u0449\u0435\u043d\u0430 \u0432 \u0420\u043e\u0436\u0434\u0435\u0441\u0442\u0432\u043e 2013, \u0441\u043f\u0443\u0441\u0442\u044f \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c 10 \u043c\u0435\u0441\u044f\u0446\u0435\u0432 \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u0445\u043e\u0434\u0430 2.0.0. \u041e\u043d\u0430 \u0432\u044b\u0448\u043b\u0430 \u0441 \u0446\u0435\u043b\u044b\u043c \u0440\u044f\u0434\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0439, \u0438 \u0434\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0441\u0442 \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u044d\u0442\u0438 \u043d\u043e\u0432\u0448\u0435\u0441\u0442\u0432\u0430.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-222941","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/222941","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=222941"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/222941\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=222941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=222941"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=222941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}