{"id":4467,"date":"2021-08-04T08:03:50","date_gmt":"2021-08-04T08:03:50","guid":{"rendered":"https:\/\/www.bearloga.space\/?page_id=4467"},"modified":"2021-08-04T08:03:50","modified_gmt":"2021-08-04T08:03:50","slug":"rubi-esli-eshhe-sluchaj-esli","status":"publish","type":"page","link":"https:\/\/www.bearloga.space\/en\/rubi-esli-eshhe-sluchaj-esli\/","title":{"rendered":"\u0420\u0443\u0431\u0438 \u2014 \u0435\u0441\u043b\u0438 \u2026 \u0435\u0449\u0435, \u0441\u043b\u0443\u0447\u0430\u0439, \u0435\u0441\u043b\u0438"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Ruby \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u044b \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445.&nbsp;\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043c \u0432\u0441\u0435 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0432 Ruby.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Ruby if \u2026 else \u0417\u0430\u044f\u0432\u043b\u0435\u043d\u0438\u0435<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">if conditional [then]\n   code...\n<\/pre>\n\n\n<p>[elsif conditional [then]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">code&#8230;]&#8230;<\/p>\n\n\n<p>[else<br \/>\ncode&#8230;]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">end<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u0435\u0441\u043b\u0438<\/em>&nbsp;\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.&nbsp;\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f&nbsp;<em>false<\/em>&nbsp;\u0438&nbsp;<em>nil<\/em>&nbsp;\u2014 false, \u0430 \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u2014 true.&nbsp;\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0420\u0443\u0431\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 elsif, \u0430 \u043d\u0435 \u0438\u043d\u0430\u0447\u0435, \u043a\u0430\u043a \u0438 elif.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442&nbsp;<em>\u043a\u043e\u0434,<\/em>&nbsp;\u0435\u0441\u043b\u0438&nbsp;<em>\u0443\u0441\u043b\u043e\u0432\u0438\u0435<\/em>&nbsp;\u0438\u0441\u0442\u0438\u043d\u043d\u043e.&nbsp;\u0415\u0441\u043b\u0438&nbsp;<em>\u0443\u0441\u043b\u043e\u0432\u0438\u0435<\/em>&nbsp;\u043d\u0435 \u0438\u0441\u0442\u0438\u043d\u043d\u043e, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f&nbsp;<em>\u043a\u043e\u0434,<\/em>&nbsp;\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 else.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u0423\u0441\u043b\u043e\u0432\u043d\u043e\u0435<\/em>&nbsp;\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 if \u043e\u0442\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0442 \u043a\u043e\u0434\u0430 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c&nbsp;<em>then<\/em>&nbsp;, \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0438\u043b\u0438 \u0442\u043e\u0447\u043a\u043e\u0439 \u0441 \u0437\u0430\u043f\u044f\u0442\u043e\u0439.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u043f\u0440\u0438\u043c\u0435\u0440<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/ruby\n\nx = 1\nif x &gt; 2\n   puts \"x is greater than 2\"\nelsif x &lt;= 2 and x!=0\n   puts \"x is 1\"\nelse\n   puts \"I can't guess the number\"\nend<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">x is 1\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u0420\u0443\u0431\u0438 \u0435\u0441\u043b\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">code if condition\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442&nbsp;<em>\u043a\u043e\u0434,<\/em>&nbsp;\u0435\u0441\u043b\u0438&nbsp;<em>\u0443\u0441\u043b\u043e\u0432\u0438\u0435<\/em>&nbsp;\u0438\u0441\u0442\u0438\u043d\u043d\u043e.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u043f\u0440\u0438\u043c\u0435\u0440<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>&nbsp;<a href=\"https:\/\/translate.googleusercontent.com\/translate_c?depth=1&amp;rurl=translate.google.ru&amp;sl=en&amp;sp=nmt4&amp;tl=ru&amp;u=http:\/\/tpcg.io\/B9LLo0&amp;xid=17259,15700022,15700186,15700190,15700256,15700259,15700262&amp;usg=ALkJrhhVWOZhcctMNf0-EwO76gEebGHXpg\" target=\"_blank\" rel=\"noreferrer noopener\">Live Demo<\/a><\/em><em>#!\/usr\/bin\/ruby $debug = 1 print &#8220;debug\\n&#8221; if $debug\u042d\u0442\u043e \u0434\u0430\u0441\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u2014debug \u0420\u0443\u0431\u0438\u043d \u0435\u0441\u043b\u0438 \u0417\u0430\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441unless conditional [then] code<\/em><\/p>\n\n\n<p>[else<br \/>\ncode ]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">end<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u00a0<em>\u043a\u043e\u0434,<\/em>\u00a0\u0435\u0441\u043b\u0438\u00a0<em>\u0443\u0441\u043b\u043e\u0432\u0438\u0435<\/em>\u00a0\u043b\u043e\u0436\u043d\u043e.\u00a0\u0415\u0441\u043b\u0438\u00a0<em>\u0443\u0441\u043b\u043e\u0432\u0438\u0435<\/em>\u00a0\u0438\u0441\u0442\u0438\u043d\u043d\u043e, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u0434, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 else.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u043f\u0440\u0438\u043c\u0435\u0440<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/ruby\n\nx = 1 \nunless x&gt;=2\n   puts \"x is less than 2\"\n else\n   puts \"x is greater than 2\"\nend<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u042d\u0442\u043e \u0434\u0430\u0441\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u2014<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">x is less than 2\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u0420\u0443\u0431\u0438, \u0435\u0441\u043b\u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">code unless conditional\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442&nbsp;<em>\u043a\u043e\u0434,<\/em>&nbsp;\u0435\u0441\u043b\u0438&nbsp;<em>\u0443\u0441\u043b\u043e\u0432\u0438\u0435<\/em>&nbsp;\u043b\u043e\u0436\u043d\u043e.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u043f\u0440\u0438\u043c\u0435\u0440<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><em>#!\/usr\/bin\/ruby $var = 1 print &#8220;1 &#8212; Value is set\\n&#8221; if $var print &#8220;2 &#8212; Value is set\\n&#8221; unless $var $var = false print &#8220;3 &#8212; Value is set\\n&#8221; unless $var\u042d\u0442\u043e \u0434\u0430\u0441\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u20141 &#8212; Value is set 3 &#8212; Value is set \u0420\u0443\u0431\u0438\u043d\u043e\u0432\u044b\u0439 \u043a\u0435\u0439\u0441\u0421\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441case expression [when expression [, expression &#8230;] [then] code ]&#8230;<\/em><\/p>\n\n\n<p>[else<br \/>\ncode ]<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">end<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442&nbsp;<em>\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435,<\/em>&nbsp;\u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u043c, \u0438&nbsp;<em>\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435<\/em>&nbsp;, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430 ===, \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442&nbsp;<em>\u043a\u043e\u0434<\/em>&nbsp;\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f when.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435,<\/em>&nbsp;\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0432 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u0438 when, \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u043b\u0435\u0432\u044b\u0439 \u043e\u043f\u0435\u0440\u0430\u043d\u0434.&nbsp;\u0415\u0441\u043b\u0438 \u043d\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f,&nbsp;<em>case<\/em>&nbsp;\u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u043e\u0434 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f&nbsp;<em>else<\/em>&nbsp;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430&nbsp;<em>when<\/em>&nbsp;\u043e\u0442\u0434\u0435\u043b\u0435\u043d\u043e \u043e\u0442 \u043a\u043e\u0434\u0430 \u0437\u0430\u0440\u0435\u0437\u0435\u0440\u0432\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0441\u043b\u043e\u0432\u043e\u043c then, \u043d\u043e\u0432\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u0438\u043b\u0438 \u0442\u043e\u0447\u043a\u043e\u0439 \u0441 \u0437\u0430\u043f\u044f\u0442\u043e\u0439.&nbsp;\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u2014<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">case expr0\nwhen expr1, expr2\n   stmt1\nwhen expr3, expr4\n   stmt2\nelse\n   stmt3\nend\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435 \u2014<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">_tmp = expr0\nif expr1 === _tmp || expr2 === _tmp\n   stmt1\nelsif expr3 === _tmp || expr4 === _tmp\n   stmt2\nelse\n   stmt3\nend<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u043f\u0440\u0438\u043c\u0435\u0440<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/usr\/bin\/ruby\n\n$age =  5\ncase $age\nwhen 0 .. 2\n   puts \"baby\"\nwhen 3 .. 6\n   puts \"little child\"\nwhen 7 .. 12\n   puts \"child\"\nwhen 13 .. 18\n   puts \"youth\"\nelse\n   puts \"adult\"\nend<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ruby \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u044b \u0432 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u044f\u0437\u044b\u043a\u0430\u0445.&nbsp;\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u043c \u0432\u0441\u0435 \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u044b, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u0432 Ruby. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[142],"tags":[],"class_list":["post-4467","page","type-page","status-publish","hentry","category-ruby"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages\/4467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/comments?post=4467"}],"version-history":[{"count":0,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/pages\/4467\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/media?parent=4467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/categories?post=4467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bearloga.space\/en\/wp-json\/wp\/v2\/tags?post=4467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}