{"id":223521,"date":"2014-05-21T13:09:02","date_gmt":"2014-05-21T09:09:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=223521"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=223521","title":{"rendered":"<span class=\"post_title\">Ruby 2.1 \u0432 \u0434\u0435\u0442\u0430\u043b\u044f\u0445 (\u0427\u0430\u0441\u0442\u044c 3)<\/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\"\/>  <\/p>\n<h5>\u041c\u0435\u0442\u043e\u0434 #singleton_class? \u0434\u043b\u044f Module\/Class<\/h5>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441\u044b Module \u0438 Class \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434 #singleton_class?, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043a\u0430\u043a \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u043e \u043e\u0436\u0438\u0434\u0430\u0442\u044c, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u043c\u0435\u0442\u0430-\u043a\u043b\u0430\u0441\u0441\u043e\u043c (singleton)<\/p>\n<pre><code class=\"ruby\">class Example   singleton_class?     #=&gt; false   class &lt;&lt; self     singleton_class?   #=&gt; true   end end <\/code><\/pre>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<h5>\u0411\u043e\u043b\u0435\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 Module#ancestors<\/h5>\n<p>  \u041c\u0435\u0442\u043e\u0434 #ancestors, \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u044b\u0439 \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u0432 \u043c\u0435\u0442\u0430-\u043a\u043b\u0430\u0441\u0441\u0443, \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0438 \u043c\u0435\u0442\u0430-\u043a\u043b\u0430\u0441\u0441\u044b, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0435\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u0443\u043f\u043e\u0440\u044f\u0434\u043e\u0447\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0432\u043e\u0434 \u043c\u0435\u0442\u0430-\u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u043d\u043e \u044d\u0442\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0435\u0441\u043b\u0438 \u043c\u043e\u0434\u0443\u043b\u044c \u0431\u044b\u043b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d \u043a \u043c\u0435\u0442\u0430-\u043a\u043b\u0430\u0441\u0441\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e prepend (\u0430 \u043d\u0435 include).<\/p>\n<pre><code class=\"ruby\">Object.ancestors.include?(Object)                                   #=&gt; true Object.singleton_class.ancestors.include?(Object.singleton_class)   #=&gt; true <\/code><\/pre>\n<h5>Object#singleton_method<\/h5>\n<p>  \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d #method \u0438 #instance_method, \u043d\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u044b \u043c\u0435\u0442\u0430-\u043a\u043b\u0430\u0441\u0441\u0430<\/p>\n<pre><code class=\"ruby\">class Example   def self.test   end    def test2   end end  # returns class method Example.singleton_method(:test)    #=&gt; #&lt;Method: Example.test&gt; # doesn't return instance method Example.singleton_method(:test2)   #=&gt; #&lt;NameError: undefined singleton method `test2' for `Example'&gt; # doesn't return inherited class method Example.singleton_method(:name)    #=&gt; #&lt;NameError: undefined singleton method `name' for `Example'&gt; <\/code><\/pre>\n<pre><code class=\"ruby\">example = Object.new  def example.test end  example.singleton_method(:test)   #=&gt; #&lt;Method: #&lt;Object:0x007fc54997a610&gt;.test&gt; <\/code><\/pre>\n<h5>Method#original_name<\/h5>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441\u0430\u0445 Method \u0438 UnboundMethod \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043c\u0435\u0442\u043e\u0434 #original_name, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u0438\u043c\u044f \u043c\u0435\u0442\u043e\u0434\u0430 \u0431\u0435\u0437 \u043f\u0441\u0435\u0432\u0434\u043e\u043d\u0438\u043c\u0430.<\/p>\n<pre><code class=\"ruby\">class Example   def foo     &quot;foo&quot;   end   alias bar foo end  example = Example.new example.method(:foo).original_name            #=&gt; :foo example.method(:bar).original_name            #=&gt; :foo Example.instance_method(:bar).original_name   #=&gt; :foo <\/code><\/pre>\n<h5>Mutex#owned?<\/h5>\n<p>  \u041c\u0435\u0442\u043e\u0434 <a href=\"http:\/\/globaldev.co.uk\/2013\/03\/ruby-2-0-0-in-detail\/#_changes\">Mutex#owned?<\/a> \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u043c, \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u043d\u0435\u043c \u0438 \u043d\u0435\u0447\u0435\u0433\u043e.<\/p>\n<h5>Hash#reject<\/h5>\n<p>  \u0412\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 Hash#reject \u0432 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0435 Hash \u0432\u044b\u0432\u0435\u0434\u0435\u0442 \u0432\u043e\u0440\u043d\u0438\u043d\u0433. \u0412 Ruby 2.2 \u0432\u044b\u0437\u043e\u0432 #reject \u0432 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430\u0445 Hash \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 Hash, \u0430 \u043d\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u0430. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0438 \u043a \u044d\u0442\u043e\u043c\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044e \u043f\u043e\u043a\u0430 \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043e \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435.<\/p>\n<pre><code class=\"ruby\">class MyHash &lt; Hash end  example = MyHash.new example[:a] = 1 example[:b] = 2  example.reject {|k,v| v &gt; 1}.class   #=&gt; MyHash <\/code><\/pre>\n<p>  \u0412\u044b\u0432\u0435\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"ruby\">example.rb:8: warning: copying unguaranteed attributes: {:a=&gt;1, :b=&gt;2} example.rb:8: warning: following atributes will not be copied in the future version: example.rb:8: warning:   subclass: MyHash <\/code><\/pre>\n<p>  \u0412 Ruby 2.1.1 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u043e \u043f\u043e\u043b\u043d\u043e\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 Hash \u0438 \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0432\u043e\u0440\u043d\u0438\u043d\u0433, \u043d\u043e \u0432 2.1.2 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e \u043d\u0430\u0437\u0430\u0434.<\/p>\n<h5>Vector#cross_product<\/h5>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441 Vector \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434 cross_product.<\/p>\n<pre><code class=\"ruby\">require &quot;matrix&quot;  Vector[1, 0, 0].cross_product(Vector[0, 1, 0])   #=&gt; Vector[0, 0, -1] <\/code><\/pre>\n<h5>Fixnum\/Bignum #bit_length<\/h5>\n<p>  \u0412\u044b\u0437\u043e\u0432 #bit_length \u043f\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044e \u043a \u0446\u0435\u043b\u043e\u043c\u0443 \u0447\u0438\u0441\u043b\u0443 \u0432\u0435\u0440\u043d\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0446\u0438\u0444\u0440, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0447\u0438\u0441\u043b\u0430 \u0432 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435.<\/p>\n<pre><code class=\"ruby\">128.bit_length                   #=&gt; 8 32768.bit_length                 #=&gt; 16 2147483648.bit_length            #=&gt; 32 4611686018427387904.bit_length   #=&gt; 63 <\/code><\/pre>\n<h5>pack\/unpack \u0438 \u0431\u0430\u0439\u0442\u043e\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u0435\u043b<\/h5>\n<p>  \u041c\u0435\u0442\u043e\u0434\u044b Array#pack \u0438 String#unpack \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0433\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0430\u0439\u0442\u043e\u0432\u044b\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0434\u043b\u0438\u043d\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0438\u0440\u0435\u043a\u0442\u0438\u0432 Q_\/Q! \u0438 q_\/q!.<\/p>\n<pre><code class=\"ruby\"># output may differ depending on the endianness of your system unsigned_long_long_max = [2**64 - 1].pack(&quot;Q!&quot;)   #=&gt; &quot;\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF&quot; signed_long_long_min = [-2**63].pack(&quot;q!&quot;)        #=&gt; &quot;\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80&quot; signed_long_long_max = [2**63 - 1].pack(&quot;q!&quot;)     #=&gt; &quot;\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\xFF\\x7F&quot;  unsigned_long_long_max.unpack(&quot;Q!&quot;)   #=&gt; 18446744073709551615 signed_long_long_min.unpack(&quot;q!&quot;)     #=&gt; -9223372036854775808 signed_long_long_max.unpack(&quot;q!&quot;)     #=&gt; 9223372036854775807 <\/code><\/pre>\n<h5>Dir.glob \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u044b<\/h5>\n<p>  \u0424\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 HFS Plus \u0432 Mac OS X \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0443 UTF8-MAC \u0434\u043b\u044f \u0438\u043c\u0435\u043d \u0444\u0430\u0439\u043b\u043e\u0432 \u0441 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u00e9 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 e \u0438 U+0301, \u0430 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e U+00E9 (<a href=\"https:\/\/developer.apple.com\/library\/mac\/qa\/qa1173\/_index.html#\/\/apple_ref\/doc\/uid\/DTS10001705-CH1-SECCOMPOSED\">\u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f\u043c\u0438<\/a>). Dir.glob \u0438 Dir[] \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u044e\u0442 \u0438\u0445 \u0432 UTF8-\u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u043c\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438.<\/p>\n<pre><code class=\"ruby\">File.write(&quot;composed_e\\u{301}xample.txt&quot;, &quot;&quot;) File.write(&quot;precomposed_\\u{e9}xample.txt&quot;, &quot;&quot;)  puts Dir[&quot;*&quot;].map(&:dump) <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"ruby\">&quot;composed_\\u{e9}xample.txt&quot; &quot;example.rb&quot; &quot;precomposed_\\u{e9}xample.txt&quot; <\/code><\/pre>\n<h5>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0434\u043b\u044f Numeric#quo<\/h5>\n<p>  \u041c\u0435\u0442\u043e\u0434 Numeric#quo \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 #to_r \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u0435, \u0447\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u043e\u0432 Numeric. \u042d\u0442\u043e \u0442\u0430\u043a\u0436\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0431\u0443\u0436\u0434\u0435\u043d\u043e TypeError, \u0430 \u043d\u0435 ArgumentError, \u0447\u0442\u043e \u043f\u0440\u0430\u0432\u0434\u0430 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0441\u0442\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435, \u0442.\u043a. TypeError \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u043a\u043b\u0430\u0441\u0441\u043e\u043c ArgumentError.<\/p>\n<h5>Binding#local_variable_get\/_set\/_defined?<\/h5>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441\u0435 Binding \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f\/\u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u0435\u0441\u043b\u0438 \u043f\u0440\u044f\u043c\u043e-\u0442\u0430\u043a\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442, \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0449\u0438\u0439 \u0441 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c.<\/p>\n<pre><code class=\"ruby\">def primes(begin: 2, end: 1000)   [binding.local_variable_get(:begin), 2].max.upto(binding.local_variable_get(:end)).each_with_object([]) do |i, array|     array &lt;&lt; i unless (2...i).any? {|j| (i % j).zero?}   end end  primes(end: 10)   #=&gt; [2, 3, 5, 7] <\/code><\/pre>\n<p>  \u0418\u043b\u0438 \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0445\u044d\u0448 \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430:<\/p>\n<pre><code class=\"ruby\">def make_binding(hash)   b = TOPLEVEL_BINDING.dup   hash.each {|k,v| b.local_variable_set(k, v)}   b end  require &quot;erb&quot;  cover = %Q{&lt;h1&gt;&lt;%= title %&gt;&lt;\/h1&gt;\\n&lt;h2 class=&quot;big friendly&quot;&gt;&lt;%= subtitle %&gt;&lt;\/h2&gt;} locals = {:title =&gt; &quot;Hitchhiker's Guide to the Galaxy&quot;, :subtitle =&gt; &quot;Don't Panic&quot;}  ERB.new(cover).result(make_binding(locals))   #=&gt; &quot;&lt;h1&gt;Hitchhiker's Guide to the Galaxy&lt;\/h1&gt;\\n&lt;h2 class=\\&quot;big friendly\\&quot;&gt;Don't Panic&lt;\/h2&gt;&quot; <\/code><\/pre>\n<h5>\u041c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 CGI \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f CGI::Util<\/h5>\n<p>  \u041a\u043b\u0430\u0441\u0441 CGI \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f url \u0438 html \u0441\u0442\u0440\u043e\u043a. \u041e\u043d\u0438 \u0431\u044b\u043b\u0438 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043d\u044b \u0432 \u043c\u043e\u0434\u0443\u043b\u044c CGI::Util, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0432\u043a\u043b\u044e\u0447\u0435\u043d \u0432 \u0434\u0440\u0443\u0433\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u0438\u043b\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u044b.<\/p>\n<pre><code class=\"ruby\">require &quot;cgi\/util&quot;  CGI.escape(&quot;hello world!&quot;)   #=&gt; &quot;hello+world%21&quot;  include CGI::Util  escape(&quot;hello world!&quot;)       #=&gt; &quot;hello+world%21&quot; <\/code><\/pre>\n<h5>Digest::Class.file \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0443<\/h5>\n<p>  \u0420\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u043c\u043e\u0434\u0443\u043b\u044f Digest \u0438\u043c\u0435\u044e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0430\u0439\u0434\u0436\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u0444\u0430\u0439\u043b\u0430, \u044d\u0442\u043e\u0442 \u043c\u0435\u0442\u043e\u0434 \u0431\u044b\u043b \u0438\u0437\u043c\u0435\u043d\u0435\u043d, \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u043d \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0443 \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u043a\u0440\u043e\u043c\u0435 \u0438\u043c\u0435\u043d\u0438 \u0444\u0430\u0439\u043b\u0430. \u0422.\u0435. \u0432\u043c\u0435\u0441\u0442\u043e:<\/p>\n<pre><code class=\"ruby\">require &quot;digest&quot; Digest::SHA2.new(512).hexdigest(File.read(&quot;example.txt&quot;))   #=&gt; &quot;f7fbba...&quot; <\/code><\/pre>\n<p>  \u041c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c:<\/p>\n<pre><code class=\"ruby\">require &quot;digest&quot; Digest::SHA2.file(&quot;example.txt&quot;, 512).hexdigest             #=&gt; &quot;f7fbba...&quot; <\/code><\/pre>\n<h5>Net::SMTP#rset<\/h5>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c SMTP-\u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044e, \u043f\u043e\u0441\u043b\u0430\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 RSET \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 Net::SMTP#rset.<\/p>\n<pre><code class=\"ruby\">require &quot;net\/smtp&quot;  smtp = Net::SMTP.start(&quot;some.smtp.server&quot;) notification = &quot;Hi %s,\\n ...&quot;  users.each do |user|   begin     smtp.mailfrom(&quot;noreply@example.com&quot;)     smtp.rcptto(user.email)     smtp.data(sprintf(notification, user.name))   rescue     smtp.rset   end end  smtp.finish <\/code><\/pre>\n<h5>open-uri \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438<\/h5>\n<p>  open-uri \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 Kernel#open \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043f\u043e URI, \u0438 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e OpenURI::Meta, \u043a\u0443\u0434\u0430 \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043d\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 #metas, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0435\u0441\u043b\u0438 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0431\u044b\u043b \u0437\u0430\u0434\u0430\u043d \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 set-cookie.<\/p>\n<pre><code class=\"ruby\">require &quot;open-uri&quot;  f = open(&quot;http:\/\/google.com&quot;) f.meta[&quot;set-cookie&quot;].class     #=&gt; String f.metas[&quot;set-cookie&quot;].class    #=&gt; Array f.metas[&quot;set-cookie&quot;].length   #=&gt; 2 <\/code><\/pre>\n<h5>\u0417\u0430\u043f\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b \u0447\u0435\u0440\u0435\u0437 Pathname<\/h5>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441 Pathname \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u043c\u0435\u0442\u043e\u0434\u044b #write \u0438 #binwrite \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0444\u0430\u0439\u043b\u043e\u0432.<\/p>\n<pre><code class=\"ruby\">require &quot;pathname&quot;  path = Pathname.new(&quot;test.txt&quot;).expand_path(__dir__) path.write(&quot;foo&quot;) path.write(&quot;bar&quot;, 3) # offset path.write(&quot;baz&quot;, mode: &quot;a&quot;) # append <\/code><\/pre>\n<h5>Tempfile.create<\/h5>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441\u0435 Tempfile \u0442\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434, \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434\u0443 new, \u043d\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 Tempfile, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 \u0444\u0438\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440(finaliser), \u0443\u0434\u0430\u043b\u044f\u044e\u0449\u0438\u0439 \u0444\u0430\u0439\u043b, \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u0434\u0432\u0435\u0440\u0433\u0430\u0435\u0442\u0441\u044f \u0441\u0431\u043e\u0440\u043a\u0435 \u043c\u0443\u0441\u043e\u0440\u0430, \u043c\u0435\u0442\u043e\u0434 create \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 File \u0432 \u0431\u043b\u043e\u043a, \u043f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0444\u0430\u0439\u043b \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f.<\/p>\n<pre><code class=\"ruby\">require &quot;tempfile&quot;  path = nil Tempfile.create(&quot;example&quot;) do |f|   f                 #=&gt; #&lt;File:\/tmp\/example20140428-16851-15kf046&gt;   path = f.path end File.exist?(path)   #=&gt; false <\/code><\/pre>\n<h5>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0433\u0440\u0443\u043f\u043f\u043e\u0432\u043e\u0433\u043e \u0432\u0435\u0449\u0430\u043d\u0438\u044f \u0432 Rinda<\/h5>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043b\u0430\u0441\u0441\u044b Rinda Ring \u043c\u043e\u0433\u0443\u0442 \u0441\u043b\u0443\u0448\u0430\u0442\u044c\/\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c\u0441\u044f \u0441 \u0433\u0440\u0443\u043f\u043f\u043e\u0432\u044b\u043c\u0438 \u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438.<\/p>\n<p>  \u041d\u0438\u0436\u0435 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Rinda \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u043f\u0440\u043e\u0441\u043b\u0443\u0448\u0438\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u0433\u0440\u0443\u043f\u043f\u043e\u0432\u043e\u0439 \u0430\u0434\u0440\u0435\u0441 239.0.0.1<\/p>\n<pre><code class=\"ruby\">require &quot;rinda\/ring&quot; require &quot;rinda\/tuplespace&quot;  DRb.start_service  tuple_space = Rinda::TupleSpace.new server = Rinda::RingServer.new(tuple_space, [&quot;239.0.0.1&quot;])  DRb.thread.join <\/code><\/pre>\n<p>  \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u0430:<\/p>\n<pre><code class=\"ruby\">require &quot;rinda\/ring&quot;  DRb.start_service ring_finger = Rinda::RingFinger.new([&quot;239.0.0.1&quot;]) tuple_space = ring_finger.lookup_ring_any  tuple_space.write([:message_service, &quot;localhost&quot;, 8080])  # start messaging service on localhost:8080 <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0430\u0434\u0440\u0435\u0441\u0430 \u0441\u0435\u0440\u0432\u0438\u0441\u0430:  <\/p>\n<pre><code class=\"ruby\"> require &quot;rinda\/ring&quot;  DRb.start_service ring_finger = Rinda::RingFinger.new([&quot;239.0.0.1&quot;]) tuple_space = ring_finger.lookup_ring_any  _, host, port = tuple_space.read([:message_service, String, Fixnum])  # connect to messaging service <\/code><\/pre>\n<p>  \u0423 \u043c\u0435\u043d\u044f \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0439 tuple_space = ring_finger.lookup_ring_any \u0438 \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"ruby\">tuple_space = nil ring_finger.lookup_ring(0.01) {|x| break tuple_space = x} <\/code><\/pre>\n<h5>\u0417\u0430\u0434\u0430\u043d\u0438\u0435 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 HTTP-\u043e\u043f\u0446\u0438\u0439 \u0434\u043b\u044f XMLRPC<\/h5>\n<p>  XMLRPC::Client#http \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 Net::HTTP, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u043e\u043f\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0437\u0430\u0434\u0430\u043d\u044b \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0442\u0442\u0435\u0440\u044b.<\/p>\n<pre><code class=\"ruby\">client = XMLRPC::Client.new(&quot;example.com&quot;) client.http.keep_alive_timeout = 30 # keep connection open for longer # use client ... <\/code><\/pre>\n<h5>URI.encode_\/decode_www_form \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u043f\u043e\u0434 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442 WHATWG<\/h5>\n<p>  \u041c\u0435\u0442\u043e\u0434\u044b URI.encode_www_form \u0438 URI.decode_www_form \u0431\u044b\u043b\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u044b \u0434\u043b\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u044f <a href=\"http:\/\/url.spec.whatwg.org\/#application\/x-www-form-urlencoded-0\">\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0443 WHATWG<\/a>.<\/p>\n<p>  URI.decode_www_form \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 <code>;<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f, <code>&<\/code> \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044c \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u0435\u043b\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 separator:.<\/p>\n<pre><code class=\"ruby\">require &quot;uri&quot; URI.decode_www_form(&quot;foo=1;bar=2&quot;, separator: &quot;;&quot;)   #=&gt; [[&quot;foo&quot;, &quot;1&quot;], [&quot;bar&quot;, &quot;2&quot;]] <\/code><\/pre>\n<p>  URI.decode_www_form \u0442\u0435\u043f\u0435\u0440\u044c \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u0434\u0435\u043a\u043e\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 URI.encode_www_form, \u043a\u043e\u0433\u0434\u0430 \u0435\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 nil.<\/p>\n<pre><code class=\"ruby\">require &quot;uri&quot;  string = URI.encode_www_form(foo: 1, bar: nil, baz: 3)   #=&gt; &quot;foo=1&bar&baz=3&quot; URI.decode_www_form(&quot;foo=1&bar&baz=3&quot;)                   #=&gt; [[&quot;foo&quot;, &quot;1&quot;], [&quot;bar&quot;, &quot;&quot;], [&quot;baz&quot;, &quot;3&quot;]] <\/code><\/pre>\n<h5>RbConfig::SIZEOF<\/h5>\n<p>  \u041d\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 RbConfig::SIZEOF \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 C-\u0442\u0438\u043f\u043e\u0432.<\/p>\n<pre><code class=\"ruby\">require &quot;rbconfig\/sizeof&quot;  RbConfig::SIZEOF[&quot;short&quot;]   #=&gt; 2 RbConfig::SIZEOF[&quot;int&quot;]     #=&gt; 4 RbConfig::SIZEOF[&quot;long&quot;]    #=&gt; 8 <\/code><\/pre>\n<h5>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 Syslog::Logger<\/h5>\n<p>  Syslog::Logger, Logger-\u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f Syslog, \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438.<\/p>\n<pre><code class=\"ruby\">require &quot;syslog\/logger&quot;  facility = Syslog::LOG_LOCAL0 logger = Syslog::Logger.new(&quot;MyApp&quot;, facility)  logger.debug(&quot;test&quot;) <\/code><\/pre>\n<h5>CSV.foreach \u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c<\/h5>\n<p>  CSV.foreach, \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u044b\u0439 \u0431\u0435\u0437 \u0431\u043b\u043e\u043a\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c, \u043d\u043e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u044d\u0442\u043e \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u043e \u043a IOError, \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e.<\/p>\n<pre><code class=\"ruby\">require &quot;csv&quot;  enum = CSV.foreach(&quot;example.csv&quot;)  enum.next   #=&gt; [&quot;1&quot;, &quot;foo&quot;] enum.next   #=&gt; [&quot;2&quot;, &quot;bar&quot;] enum.next   #=&gt; [&quot;3&quot;, &quot;baz&quot;] <\/code><\/pre>\n<h5>OpenSSL bignum<\/h5>\n<p>  OpenSSL::BN.new \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a\u0438, \u043d\u043e \u0438 \u0446\u0435\u043b\u044b\u0435 \u0447\u0438\u0441\u043b\u0430.<\/p>\n<pre><code class=\"ruby\">require &quot;openssl&quot;  OpenSSL::BN.new(4_611_686_018_427_387_904)   #=&gt; #&lt;OpenSSL::BN:0x007fce7a0c56e8&gt; <\/code><\/pre>\n<h5>\u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442 size Enumerator.new \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043b\u044e\u0431\u043e\u0439 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442<\/h5>\n<p>  Enumerator.new \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0430\u0440\u0433\u043c\u0435\u043d\u0442 size, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u0446\u0435\u043b\u044b\u043c \u0447\u0438\u0441\u043b\u043e\u043c, \u0442\u0430\u043a \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c #call. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043e 2.0.0 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0446\u0435\u043b\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438 \u0438 Proc-\u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438. \u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0435\u043d\u043e \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438.<\/p>\n<pre><code class=\"ruby\">require &quot;thread&quot;  queue = Queue.new enum = Enumerator.new(queue.method(:size)) do |yielder|   loop {yielder &lt;&lt; queue.pop} end queue &lt;&lt; &quot;foo&quot; enum.size   #=&gt; 1 <\/code><\/pre>\n<h5>\u0423\u0434\u0430\u043b\u0435\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 curses<\/h5>\n<p>  curses \u0431\u044b\u043b\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0430 \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 <a href=\"https:\/\/rubygems.org\/gems\/curses\">\u0433\u0435\u043c\u0430<\/a>.<\/p>\n<h5>\u041c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430 \u0432 TSort<\/h5>\n<p>  \u041a\u043b\u0430\u0441\u0441 TSort \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u0435\u043d \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. \u041e\u0434\u043d\u0430\u043a\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0445\u043b\u043e\u043f\u043e\u0442\u043d\u043e, \u0434\u043b\u044f \u0438\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0439 TSort, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u0435\u0442\u043e\u0434\u044b #tsort_each_node \u0438 #tsort_each_child.<\/p>\n<p>  \u041d\u043e \u0442\u0435\u043f\u0435\u0440\u044c TSort \u0441\u0442\u0430\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0445\u044d\u0448\u0430\u043c\u0438. \u041c\u0435\u0442\u043e\u0434\u044b, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434\u044b \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 \u0441\u0430\u043c\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044f \u0434\u0432\u0430 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043e\u0434\u0438\u043d \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u0430\u043c\u0435\u043d\u044b #tsort_each_node, \u0432\u0442\u043e\u0440\u043e\u0439 \u2014 #tsort_each_child.<\/p>\n<pre><code class=\"ruby\">require &quot;tsort&quot;  camping_steps = {   &quot;sleep&quot; =&gt; [&quot;food&quot;, &quot;tent&quot;],   &quot;tent&quot; =&gt; [&quot;camping site&quot;, &quot;canvas&quot;],   &quot;canvas&quot; =&gt; [&quot;tent poles&quot;],   &quot;tent poles&quot; =&gt; [&quot;camping site&quot;],   &quot;food&quot; =&gt; [&quot;fish&quot;, &quot;fire&quot;],   &quot;fire&quot; =&gt; [&quot;firewood&quot;, &quot;matches&quot;, &quot;camping site&quot;],   &quot;fish&quot; =&gt; [&quot;stream&quot;, &quot;fishing rod&quot;] }  all_nodes = camping_steps.to_a.flatten each_node = all_nodes.method(:each) each_child = -&gt; step, &b {camping_steps.fetch(step, []).each(&b)} puts TSort.tsort(each_node, each_child) <\/code><\/pre>\n<p>  \u0412\u044b\u0432\u0435\u0434\u0435\u0442:<\/p>\n<pre><code class=\"ruby\">stream fishing rod fish firewood matches camping site fire food tent poles canvas tent sleep <\/code><\/pre>\n<h5>TCP Fast Open<\/h5>\n<p>  \u0412 Ruby 2.1 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 <a href=\"http:\/\/lwn.net\/Articles\/508865\/\">TCP Fast Open<\/a>, \u0435\u0441\u043b\u0438 \u043e\u043d \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 \u0432\u0430\u0448\u0435\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u0414\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u043d\u0430 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0435\u0433\u043e \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442 Socket::TCP_FASTOPEN \u0438 Socket::MSG_FASTOPEN.<\/p>\n<p>  \u0421\u0435\u0440\u0432\u0435\u0440:<\/p>\n<pre><code class=\"ruby\">require &quot;socket&quot;  unless Socket.const_defined?(:TCP_FASTOPEN)   abort &quot;TCP Fast Open not supported on this system&quot; end  server = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM) server.setsockopt(Socket::SOL_TCP, Socket::TCP_FASTOPEN, 5) addrinfo = Addrinfo.new(Socket.sockaddr_in(3000, &quot;localhost&quot;)) server.bind(addrinfo) server.listen(1)  socket = server.accept socket.write(socket.readline) <\/code><\/pre>\n<p>  \u041a\u043b\u0438\u0435\u043d\u0442:<\/p>\n<pre><code class=\"ruby\">require &quot;socket&quot;  unless Socket.const_defined?(:MSG_FASTOPEN)   abort &quot;TCP Fast Open not supported on this system&quot; end  socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM) socket.send(&quot;foo\\n&quot;, Socket::MSG_FASTOPEN, Socket.sockaddr_in(3000, &quot;localhost&quot;)) puts socket.readline socket.close <\/code><\/pre>\n<p>  <a href=\"http:\/\/habrahabr.ru\/post\/222941\/\">\u041f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a> <a href=\"http:\/\/habrahabr.ru\/post\/223209\/\">\u0412\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c<\/a>   \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\/223521\/\"> http:\/\/habrahabr.ru\/post\/223521\/<\/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\"\/>  <\/p>\n<h5>\u041c\u0435\u0442\u043e\u0434 #singleton_class? \u0434\u043b\u044f Module\/Class<\/h5>\n<p>  \u0412 \u043a\u043b\u0430\u0441\u0441\u044b Module \u0438 Class \u0431\u044b\u043b \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043c\u0435\u0442\u043e\u0434 #singleton_class?, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043a\u0430\u043a \u0438 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u043e \u043e\u0436\u0438\u0434\u0430\u0442\u044c, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u0435\u043b\u044c \u043c\u0435\u0442\u0430-\u043a\u043b\u0430\u0441\u0441\u043e\u043c (singleton)<\/p>\n<pre><code class=\"ruby\">class Example   singleton_class?     #=&gt; false   class &lt;&lt; self     singleton_class?   #=&gt; true   end end <\/code><\/pre>\n<p>  <\/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-223521","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/223521","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=223521"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/223521\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=223521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=223521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=223521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}