ruby
ã¿ã¤ãã«ã®ã¨ãããCodeIQã®ããã»ã«ã³ãã»ã¤ã¯ã¨ã¤ã·ã§ã³ãåé¡ãã®æ²è¼æéãçµäºããã¨ãããã¨ã§ããããã®æåºã³ã¼ãããããã¦ããããã¨æãã¾ãã使ç¨è¨èªã¯Rubyã1åã®æåºã§éã£ãè¨æ¶ãããã¾ã(èªåæ¡ç¹ãªã®ã§å¿ããã¡)ã ã¢ã«ã´ãªãºã ã«ã¤ãã¦â¦
ã¿ã¤ãã«ã®éãCodeIQãã¨ã¼ã¹ã»ãã³ãã¼ãåé¡ã®æ²è¼æéãçµãã£ãã¨ã®ãã¨ã§ãèªåã®æåºã³ã¼ãããããã¦ããã¾ãã使ç¨è¨èªã¯Ruby ãèªåæ¡ç¹ã¨ãããã¨ãããè¨æ¶ãããã¾ãã§ããã確ãä¸çºåæ ¼ã ã£ããããªæ°ããã¾ãã 詳細ã«ã¤ãã¦ã¯ãããã®ã§æâ¦
é£æ度é«ãã ã£ãã¨ããåã®åé¡ãå®éé£ããã£ãã¨æãã¾ããå人çã«ã¯æå¾ å¤ããããããè¦æãªã®ã§ãä½è¨ã«å¤§å¤ã§ãããã§ãããªãã¨ãåçã§ããã®ã§ããã®ã³ã¼ããããã«ãããã¦ããã¾ãã 使ç¨è¨èªã¯Rubyã1åç®ã®æåºã§ç¡äºåæ ¼ã§ããã ä»åã¯åé¡â¦
ãã«ããã»ã¢ã³ãã»ã¹ã¯ã¨ã¢ãåé¡ | CodeIQ å°±è·æ´»åãè½ã¡çãã¦ããã¨ã¯ãããã¾ã ã°ãã°ãã¯ãã¦ããã®ã§ãç°¡åã«ã¾ã¨ãã¦ããã¾ããæ£ç´ãªã¨ãããããããæ¸ããã°ãªããªãã»ã©ã®ãã¨ã¯ãã¦ãã¾ãããããã¨ã¯ã8æåºç¤ã§å°±æ´»è½ã¡çãã¡ãã¾ããã§ããâ¦
æè¿ã¯ããã°ã©ãã³ã°ã³ã³ãã¹ãçãªãã®ãå©ç¨ãã¦ããã°ã©ãã³ã°ãåå¼·ãã¦ããã®ã§ããããã®éå¤éã«ã¼ããæ¸ããã¨ãé »ç¹ã«ãã¨ãããã¾ãã (1..3).each do |i| (1..3).each do |j| p [i, j] end end ä¸ã®ä¾ãªã©ã¯å ¸åçã§ãããå人çãªç¾å¦ããããâ¦
ããã°ã©ãã³ã°ã»ã³ã³ãã¹ãçãªãã®ã解ãã¦ããã¨ããæ¨æºå ¥åããä¸è¡ãã¤åãåããé åã«æ ¼ç´ãããã¨ããå¦çãæ¸ããã¨ããã°ãã°æ±ãããã¾ããããããã¨ãããããã¯ä»¥ä¸ã®ããã«æ¸ãã¦ãã¾ããããããä¸è¬çãªæ¹æ³ã§ããã¨ãæãã¾ãã lines = â¦
èªåã®æ¥ããããã¨ãããããæè¿ã¾ã§ããã¼ã¸ããåã«é åãåå¾ã«çµåãããã¨ã ã¨æã£ã¦ãã¾ããâ¦â¦ã [1,2] + [3,4,5] => [1,2,3,4,5] ãã®ããã§ããã¼ã¸ã½ã¼ãããªããã®ããã£ã±ãç解ã§ãããããã¶ãã¨é·ãéå¦ç¿ãæ¾æ£ãã¦ãã¾ããâ¦â¦ãå人çã«åâ¦
å·éã«è¦è¿ãã¦ã¿ãã¨ãåçç¹ãå±±çãã§ããâ¦â¦ããµã ãããã«ä½ãèãã¦ããªããããããã¾ãã ããã£ãºã»ããºã»ã¨ã¯ã¹ããªã¼ã ãã¨ã¯ ããã£ãºããºã»ã¨ã¯ã¹ããªã¼ã ãã¨ã¯ãªã¯ã«ã¼ããã£ãªã¢ç¤¾ãéå¶ããââã£ã¦ããã®æã®ãã¨ã¯ä»¥åã«ä½åº¦ãæ¸ããã®ã§ãâ¦
ã¡ã¿ããã°ã©ãã³ã°Rubyä½è : Paolo Perrotta,è§å¾å ¸åºç社/ã¡ã¼ã«ã¼: KADOKAWA/ã¢ã¹ãã¼ã»ã¡ãã£ã¢ã¯ã¼ã¯ã¹çºå£²æ¥: 2010/08/28ã¡ãã£ã¢: 大åæ¬è³¼å ¥: 18人 ã¯ãªãã¯: 533åãã®ååãå«ãããã° (125件) ãè¦ã Rubyããã°ã©ãã®ä¸ã§é常ã«è©ä¾¡ãé«ããã¡ã¿â¦
以åã¯ã¦ã¼ã¯ãªããã®äºé¤æ³ããããããããæ ä¿ãã¤ã¤ãã§ããã ãçãå®è£ ãã¾ããã rubyã§ã¦ã¼ã¯ãªããã®äºé¤æ³ãçãå®è£ ãããã - nekoTheShadowâs diary ä»åã¯åããã¨ãã¯ã¤ãã¯ã½ã¼ãã§ãã¦ã¿ããã¨ããè¨äºã«ãªãã¾ãã ããããã¯ã¤ãã¯ã½ã¼ãâ¦
9ããºã«ã¨ã¯? 9ããºã«ã¨ã¯ç¸¦ã«3æã横ã«3æãåè¨9æã®ããã«ãå ¥ãæ£æ¹å½¢ã®æ ã«ã1ãã9ã¾ã§ã®æ°åãæ¸ããã8æã®ããã«ãåãè¾¼ã¾ããããºã«ã§ããã¤ã¾ãæ å ã«ã¯ä¸æåã®ç©ºç½ãããããã®ç©ºç½ã«é£ãåã£ãããã«ãã¹ã©ã¤ããããªãããã°ããã¦ããæ°åâ¦
YO! yo!langã¨ã¯ yo!langã¯ãããããé£è§£ããã°ã©ãã³ã°è¨èªã(esolang)ã®ã²ã¨ã¤ã§ããyo YO Yo! Yo? YO! yo? yo! YO?ã®8ã¤ã®å½ä»¤ãããªãã«ããããããããã¥ã¼ãªã³ã°å®å ¨ã§ãããããããã°ã©ãã³ã°è¨èªã¨åç¨åº¦ã®ãã¨ãå¯è½ã«ãªã£ã¦ãã¾ãââã¨æ¸ãã¨åâ¦
<ä»é±ã®ãé¡ãæè¿ãããããã£ãæ¬ã>ã¨ããä¼ç»ãç¥ã£ãã®ã§ã便ä¹æ稿ãã¦ã¿ããã¨æãã¾ãã ãªã¬ã³ã¸ã»ã¢ã³ãã»ã¿ã¼ã« (å æ社æ庫)ä½è : è¤æ²¢å¨åºç社/ã¡ã¼ã«ã¼: å æ社çºå£²æ¥: 2010/12/09ã¡ãã£ã¢: æåº«è³¼å ¥: 2人 ã¯ãªãã¯: 15åãã®ååãå«ãããã°â¦
説æä¼ã¤ããå±¥æ´æ¸ã¤ããã¨ã³ããªã¼ã·ã¼ãã¤ããã°ã«ã¼ããã£ã¹ã«ãã·ã§ã³ã¤ããéå£é¢æ¥ã¤ããå人é¢æ¥ã¤ããã¤ããã¤ããã¤ããã¤ããã¤ãããããããããããããããã (´ã»Ïã»ï½) ããã¤ããªã»ã«ã¦ã³ããã¨ã¯ ããã¤ããªã»ã«ã¦ã³ããåé¡ | CodeIQ ãâ¦
æè¿ãããããªã¢ã«ã´ãªãºã ãçãçããããã¨ã«ã¯ã¾ã£ã¦ãã¾ããä»æ¥ã¯ãã®ä¸ç°ã§ã¦ã¼ã¯ãªããã®äºé¤æ³ãæ±ãã¾ããã ã¦ã¼ã¯ãªããã®äºé¤æ³ã¨ã¯ä½ã ã¦ã¼ã¯ãªããã®äºé¤æ³ã¯æå¤§å ¬ç´æ°ãæ¢ãå®çªã¢ã«ã´ãªãºã ã§ããã·ã³ãã«ãªããé常ã«å¼·åã§ããããä¸â¦
å ¬éãã¦ãããããã¨æè¿ç¥ã£ãã®ã§ã ãpaiza ãªã³ã©ã¤ã³ããã«ã½ã³ãã¨ã¯? ããããpaizaã¨ã¯ã®ãæ ªå¼ä¼ç¤¾ãéå¶ãã¦ãããããã°ã©ããã·ã¹ãã ã¨ã³ã¸ãã¢åãã®è»¢è·ãµã¤ãã§ããç¹å¾´ã¨ãã¦ã¯ãããã°ã©ãã³ã°ã¹ãã«ãå³ããããã¨ãããã¨ãå®ã®ã¨ããâ¦
ãã¨ãã°ã¤ã³ããã¯ã¹ã1ããå§ã¾ãé å(ãã©ã)ããã¤ããã¯ã©ã¹ãä½ãããã¨ãã¾ããã¨ããããååã¯Tableã¨ã§ããã¾ããããã class Table # å¼æ°ã¯ArrayãTable.new([1,2,3,4]) def initialize(ary) @table = ary.dup end end ãã®ã¯ã©ã¹ã«ããã¦ãã¤â¦
就活ãã¤ããã§ã(´ã»Ïã»ï½)æè¿ã¯ã¨ãã«ã¨ã³ããªã¼ã·ã¼ãæåºã®ç· ãåããç¶ãã¦ãã¦æ¬å½ã«ã¤ãã(´ã»Ïã»`) ã ãã代ããã«æ¸ãã¦ãããªããããããã¨ã³ããªã¼ã·ã¼ã代è¡ä¼ç¤¾ãã¨ãããã°ãããããããæè¿ã¯ã塾éããç¿ãäºã§å¿ããåä¾åãã®ã宿é¡ä»£â¦
注æï¼ãã®è¨äºã¯ç¸å½ããããããªç¶æ ã§æ¸ãã¦ãã¾ãããã ã§ããä¼ãã¥ããå 容ãä½è¨ã«ããããããªããªã£ã¦ããå¯è½æ§ãããã¾ããããããã rubyã®ãåå¼·ä¸ã次ã®ãããªã¡ã½ãããå¿ è¦ã«ãªãã¾ããã ary1 = [1,2,2,3] ary2 = [2,3,4] p ary1.diff(aryâ¦
each_with_objectã®ä¾¿å©ãã«éç¼ããã - nekoTheShadowâs diaryä¸æ¨æ¥ã®è¨äºã§ (0..2).inject({}) do |hash,num| hash[num] = num end ã¯ãã¾ããããªããã (0..2).inject({}) do |hash,num| hash[num] = num hash end ã¯ãã¾ããããã¨ããå 容ãæ¸ãã¾ãâ¦
説æãã¥ããã¦ç³ã訳ãªãã®ã§ãããrubyã®åå¼·ä¸ã«æ¬¡ã®ãããªå¦çããããã¨ãªãã¾ããã hash = {} (0..2).each do |num| hash[num] = num end p hash #=> {0=>0, 1=>1, 2=>2} ä½ããã®ãªãã¸ã§ã¯ããã«ã¼ãã§ã¾ããã¦ãããã·ã¥ã«çªã£è¾¼ãã§ããããã§ãâ¦
mapã¯åè¦ç´ ã«å¯¾ãã¦ãããã¯ãè©ä¾¡ããçµæã®é åãè¿ãã便å©ãªã¡ã½ããã§ãããä»æ¥ã¯ãã®åå¼·ä¸ã«ãè©ä¾¡ã®å¯¾è±¡ã¨ãã¦ã¬ã·ã¼ãã®ã¤ã³ããã¯ã¹ãå©ç¨ãããã¨ãªãã¾ããã nums = [1,2,3] multipled_nums = [] nums.each_with_index do |num,idx| multipleâ¦
rubyã®Hashã¯ã©ã¹ã®ã¯ã©ã¹ã¡ã½ããnewã¯å¼æ°ã«ãããã¯ãã¨ããã¨ãã§ãããã¨ã¯ããç¥ããã¦ãã¾ãã hash = Hash.new do |hash,key| if key.even? val = "å¥æ°" else # key.odd? val = "å¶æ°" end hash[key] = val end p hash[1] #=> "å¶æ°" p hash #=> {1â¦
rubyã®ãåå¼·ä¸ã次ã®ãããªé åãã»ããã¨ãªãã¾ããã [[true, false, false, false], [false, false, false, false], [false, false, false, false], [false, false, false, false]] æ£æ¹å½¢ã®å·¦ç«¯ã ããtrueãæ®ãã¯å ¨é¨falseã¨ããã¤ã¡ã¼ã¸ãç°¡åããã§â¦
rubyã§ã¯æ°å¤ã®å ¥ãæ¿ãçãªãã¨ãç°¡åã«ã§ãããã¨ãç¥ããã¦ãã¾ãã ã¤ã¾ãã¯ãããªæãã x = 1 y = 2 x,y = y,x p x #=> 2 p y #=> 1 é åã®å ´åãåãã§ãã ary = [0,1] ary[0], ary[1] = ary[1], ary[0] p ary #=> [1,0] ãã¨ãã°å¤æ°å®£è¨ã®ã¨ããä¸â¦
rubyã¯ç´ æµãªããã°ã©ãã³ã°è¨èªã ã¨æãã¾ãããä¸æºã«æããªãã¨ããããªããã¨ããã¨â¦â¦å人çã«ä¸çªã©ãã«ããªããªããã¨æãã®ã¯ãArrayã®ã¯ã©ã¹ã¡ã½ããã§ãã delete delete_at delete_if ã®ä»æ§ã§ãããããã©ãããã®ã§ãä»®ã«ãã®3種ãdeleteç³»ã¨å¼â¦
æ¨æ¥ã¯æ¨æ¥ããè¦ã¦ãã¨ã¨ãã®ä¿®æ£ããã¾ããããä»æ¥ã¯ä»æ¥ããè¦ã¦ãã¨ã¨ãã®è¨äºã®ä¿®æ£ããã¾ãã ãããã確ããã¦ããæ¸ããªããããããããã¨ã«ãªããã ããã¨ã¨ãã®ãã¨ã§ããã次ã®ãããªè¨äºãæ¸ãã getthumbininfoã§æ稿è æ å ±ãåå¾ãã¦ã¿ããâ¦
rubyã§POSTãããã¦ãã¹ãããã·ã§ããæ¤ç´¢APIãã - nekoTheShadowâs diary ä¸æ¨æ¥æ¸ããè¨äºã«æ¬¡ã®ãããªã³ã¼ããä¹ãã¾ããã å®ã¯ããã«ã¯ãã種ã®æ¬ é¥ãããã¾ãããä¸è¨ã³ã¼ãã«ããã¦ãåºåãæ´ããé¨åã§æ¬¡ã®ããã«æ¸ããã®ã§ããâ¦â¦ puts res.scan(/â¦
æ¨æ¥ããã³ãã³åç»æä¾ã®ãã¹ãããã·ã§ããæ¤ç´¢APIãã§ãåç»æ稿è ã«é¢ããæ å ±ãåããªãã¨ãä½ã¨ãã¨ãã¶ã¤ããæ¸ããã®ã§ããããã®å¾ãã¤ã³ã¿ã¼ããããµã¼ãã£ã³ããã¦ããã¨ãå¥ã®apiã§æ稿è æ å ±ã¯åå¾ã§ãããã¨ãå¤æã ãgetthumbinfoãã¨ãããâ¦
ãrubyã§POSTã£ã¦ã©ããããã ãããã¨ããã®ããµã¨é ã«æãæµ®ãã³ã¾ãã¦ãæ¸ãã¦ã¿ã¾ããã require "net/http" # urlã«ã¯postå ã®urlããdataã«ã¯postããããã¼ã¿ãå ¥ããã def httpPost(url,data) uri = URI.parse(url) http = Net::HTTP.start(uri.hosâ¦