{"id":407,"date":"2018-06-25T23:33:06","date_gmt":"2018-06-25T20:33:06","guid":{"rendered":"http:\/\/www.scozturk.com\/?p=407"},"modified":"2025-08-29T07:26:25","modified_gmt":"2025-08-29T07:26:25","slug":"ruby-ii-kullanici-girisi-almak","status":"publish","type":"post","link":"http:\/\/18.193.70.38\/?p=407&lang=tr","title":{"rendered":"Ruby &#8211; II &#8211; Kullan\u0131c\u0131 Giri\u015fi Almak"},"content":{"rendered":"<p><em><strong>Giri\u015f<\/strong><\/em><br \/>\nBu yaz\u0131da <em>Ruby<\/em> ile kullan\u0131c\u0131 girdilerinin en basit y\u00f6ntemlerle nas\u0131l al\u0131nabildi\u011fini g\u00f6rece\u011fiz.<\/p>\n<p><em><strong>Komut Sat\u0131r\u0131 Arg\u00fcman\u0131 Varl\u0131\u011f\u0131 Kontrol<\/strong><\/em><br \/>\nKullan\u0131c\u0131lardan girdi alman\u0131n ilk y\u00f6ntemi do\u011frudan yaz\u0131l\u0131m \u00e7al\u0131\u015ft\u0131r\u0131l\u0131rken giri\u015fte arg\u00fcmanlar ile girdi almaktad\u0131r. Bunun i\u00e7in a\u015fa\u011f\u0131daki \u00f6rne\u011fi inceleyelim:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# K\u00fct\u00fcphaneleri y\u00fckle\nrequire 'rubygems'\n\n# Bo\u015f arg\u00fcman kontorl\u00fc yap\nif ARGV.empty?\n  puts &quot;Hata: Arg\u00fcman yok!&quot;\n  exit\nend\n\n# Arg\u00fcman adedi de kontrol et\nif ARGV.length &lt; 2\n    abort &quot;Hata: 2 veya daha fazla adet arg\u00fcman girilmedi!&quot;\nend\n<\/pre>\n<p>Ruby&#8217;de yaz\u0131l\u0131m arg\u00fcmanlar\u0131 <em>ARGV<\/em> de\u011fi\u015fkeni ile yaz\u0131l\u0131mc\u0131ya sunulmaktad\u0131r. &#8220;<em>.empty?<\/em>&#8221; sorgusu ile bu de\u011fi\u015fkenin bo\u015f olup olmad\u0131\u011f\u0131na bak\u0131labilir, bo\u015fsa bir arg\u00fcman bulunmuyor demektedir. <em>ARGV<\/em> dolu oldu\u011funda ise genel olarak yeterli adette kullan\u0131c\u0131 girdisinin olup olmad\u0131\u011f\u0131n\u0131 sorgulamak gerekmektedir. Bunun i\u00e7in <em>ARGV<\/em> dizisinin boyutu &#8220;<em>.length<\/em>&#8221; ile kontrol edilebilmektedir.<\/p>\n<p><em><strong>Komut Sat\u0131r\u0131 Arg\u00fcmanlar\u0131 Almak<\/strong><\/em><br \/>\nYaz\u0131l\u0131m \u00e7al\u0131\u015ft\u0131r\u0131l\u0131rken girilen arg\u00fcmanlar farkl\u0131 y\u00f6ntemlerle de\u011fi\u015fkenlere atanabilmektedir. Bir \u00f6rnek a\u015fa\u011f\u0131daki gibidir:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# K\u00fct\u00fcphaneleri y\u00fckle\nrequire 'rubygems'\n\n# Arg\u00fcmanlar\u0131 de\u011fi\u015fkenlere ata\nparametre1 \t= ARGV&#x5B;0]\nparametre2 \t= ARGV&#x5B;1]\n\n# De\u011fi\u015fkenleri ekrana yazd\u0131r\nputs parametre1\nputs parametre2\n<\/pre>\n<p>Ba\u015fka bir y\u00f6ntem de a\u015fa\u011f\u0131daki gibidir:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# K\u00fct\u00fcphaneleri y\u00fckle\nrequire 'rubygems'\n\n# Arg\u00fcmanlar\u0131 de\u011fi\u015fkenlere ata\ntest1, test2 = ARGV\n\n# Arg\u00fcmanlar\u0131n bulundu\u011fu de\u011fi\u015fkenleri yazd\u0131r\nputs &quot;\u0130lk arg\u00fcman: #{test1}&quot;\nputs &quot;\u0130kinci arg\u00fcman: #{test2}&quot;\n<\/pre>\n<p><em><strong>Komut Sat\u0131r\u0131ndan Girdi Almak<\/strong><\/em><br \/>\nBir <em>Ruby<\/em> yaz\u0131l\u0131m\u0131 \u00e7al\u0131\u015f\u0131rken de kullan\u0131c\u0131 girdileri al\u0131nabilmektedir. Bunun i\u00e7in:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# K\u00fct\u00fcphaneleri y\u00fckle\nrequire 'rubygems'\n\n# \u0130lk de\u011feri sorgula ve al\nputs &quot;Bir veri giriniz:&quot;\ndeger1 = $stdin.gets\n\n# \u0130kinci de\u011feri sorgula ve al\nputs &quot;Ba\u015fka bir veri giriniz&quot;\ndeger2 = $stdin.gets\n\n#  De\u011ferleri ekrana yazd\u0131r\nputs deger1\nputs deger2\n<\/pre>\n<p>Girilen de\u011ferleri say\u0131 olarak ele almak i\u00e7in:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# K\u00fct\u00fcphaneleri y\u00fckle\nrequire 'rubygems'\n\n# \u0130lk de\u011feri sorgula ve al\nputs &quot;Bir veri giriniz:&quot;\ndeger1 = $stdin.gets.to_i\n\n# \u0130kinci de\u011feri sorgula ve al\nputs &quot;Ba\u015fka bir veri giriniz&quot;\ndeger2 = $stdin.gets.to_i\n\n#  De\u011ferleri ekrana yazd\u0131r\nputs deger1+deger2\n<\/pre>\n<p><em><strong>Sonu\u00e7<\/strong><\/em><br \/>\nEn basit haliyle <em>Ruby<\/em>&#8216;den girdi alman\u0131n birka\u00e7 yolunu g\u00f6rd\u00fck. Umar\u0131m i\u015finize yarar, iyi kodlamalar!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Giri\u015f Bu yaz\u0131da Ruby ile kullan\u0131c\u0131 girdilerinin en basit y\u00f6ntemlerle nas\u0131l al\u0131nabildi\u011fini g\u00f6rece\u011fiz. Komut Sat\u0131r\u0131 Arg\u00fcman\u0131 Varl\u0131\u011f\u0131 Kontrol Kullan\u0131c\u0131lardan girdi alman\u0131n ilk y\u00f6ntemi do\u011frudan yaz\u0131l\u0131m \u00e7al\u0131\u015ft\u0131r\u0131l\u0131rken giri\u015fte arg\u00fcmanlar&#8230;<\/p>\n","protected":false},"author":1,"featured_media":427,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[225,237,191],"tags":[],"class_list":["post-407","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programlama-tr","category-ruby-tr","category-teknik-tr"],"_links":{"self":[{"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/posts\/407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/18.193.70.38\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=407"}],"version-history":[{"count":1,"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/posts\/407\/revisions"}],"predecessor-version":[{"id":1196,"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/posts\/407\/revisions\/1196"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/18.193.70.38\/index.php?rest_route=\/wp\/v2\/media\/427"}],"wp:attachment":[{"href":"http:\/\/18.193.70.38\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/18.193.70.38\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=407"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/18.193.70.38\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}