5分でわかる Ruby を知らない人が Ruby の便利さを学べる記事をかいたよ
ã£ã¦è¨äºããã£ã¦ã¨ã£ã¦ãæåãã¾ãããRubyã§ã¯Railsã¨ãSinatraã¨ãã®Webã¢ããªã®ãã¬ã¼ã ã¯ã¼ã¯ãæµè¡ã£ã¦ãã¾ããããã£ã¨ãæ軽ã«ã¡ãã£ã¨ä¾¿å©ãªä½¿ãæ¹ãç´¹ä»ããã®ã£ã¦ããã§ãããï¼ï¼
ãã æ¸ãæ¹ãå°ãåé·ãªã³ã¼ããå¤ãã¦ã元ネタのPHPãããRubyãé·ã£ããããã¨èª¤è§£ããã¦ãã¾ã£ã¦ããç¯ãããã¾ãã
ããã¡ãã£ã¨çãæ¸ãããï¼ï¼
ã£ã¦ãã¨ã§æ¸ããªããã¦ã¿ã¾ããã
>ã³ãã¼ã©ã¤ãã®è¥¿æ¦ãèªåæ´æ°
>Ruby ã使ãã°ãã¼ã¸ããã¿ã®è¥¿æ¦ãèªåæ´æ°ãã¾ãã
before
Copyright (c) 20010-<%= Time.now.strftime("%Y") %> Weble inc. All Rights Reserved.
Time#yearã£ã¦ã¡ã½ãããããã®ã§ãã£ã¡ä½¿ã£ãã»ããç´ ç´ã§ããã
after
Copyright (c) 2010-<%= Time.now.year %> Weble inc. All Rights Reserved.
>ä»äººã®ãµã¤ãã®å 容ãèªã¿è¾¼ã
before
<%= require 'open-uri' open("http://google.com/") do |f| f.each do |line| puts line end end %>
htmlãããã®é·ãã®ãã®ã§ããã°IO#readã使ã£ã¦åé¡ãªãã
#ãããç¸å¯¾ãªã³ã¯ã«å¯¾å¿ã§ãã¦ãªãã®ã§ã¾ã¨ãã«ä½¿ããªããiframeã¨ã使ãã¹ã
after
<%= require 'open-uri' puts open("http://google.com/").read %>
>è¤æ°ã®ã¡ãã»ã¼ã¸ãã©ã³ãã ã«è¡¨ç¤º
before
<%= if RUBY_VERSION < '1.9.0' class Array def choice at( rand( size ) ) end end end message = ["ã¡ãã»ã¼ã¸A", "ã¡ãã»ã¼ã¸B", "ã¡ãã»ã¼ã¸C", "ã¡ãã»ã¼ã¸D", "ã¡ãã»ã¼ã¸E"] message.choice %>
ãã®ã³ã¼ããat()ãself[]ã«ããã°1.8ã§ãåãã¾ããã
ã§ãArray#choice追å ããã®ããããã§ããã
âã®ã§ããã§ããããªãªã¸ãã«ã®PHPããããªãããã ãã
after
<%= message = ["ã¡ãã»ã¼ã¸A", "ã¡ãã»ã¼ã¸B", "ã¡ãã»ã¼ã¸C", "ã¡ãã»ã¼ã¸D", "ã¡ãã»ã¼ã¸E"] message[rand(message.size)] %>
>æå®ããæã®ã«ã¬ã³ãã¼ãåºå
>å°ãé·ãã§ããã2010å¹´12æã®ã«ã¬ã³ãã¼ãåºåãã¾ãã
before
<%= require 'date' def calender(year, month) jpweek = ['æ¥', 'æ', 'ç«', 'æ°´', 'æ¨', 'é', 'å'] date = DateTime::new(year, month, 1) date = (date >> 1) - 1 days = date.day one = Date::new(2010,12,1) week = one.wday day = Array.new(42) days.times{|i| day[week + i] = i + 1 } calender = '<table><tr>' jpweek.each{ |i| calender << '<th>' + i.to_s + '</th>' } calender << '</tr>' key = 0 day.each{|i| if key.to_i % 7 == 0 then calender << '<tr>' end calender << '<td>' if i != nil calender << i.to_s else calender << ' ' end if key.to_i % 7 == 6 calender << '</tr>' end key += 1 } calender << '</table>' return calender; end print calender(2010, 12) %>
- å¼æ°ã®year, monthãçµå±ä½¿ããã¦ãªã
- æ¥æ°ã®è¨ç®ããã¦ããªãã®ã§2æã§ã31æ¥ã¾ã§ã§ã
- calenderãããªãã¦calendarã (確èªãããPHPçã§æ¢ã«ééã£ã¦ãã((((ï¼ï¾Ðï¾)))) )
ã¨ããã°ãç®ç«ã¡ã¾ããPHPã®ã³ã¼ããportã§ãã¦ãªãã
Dateã¯ã©ã¹ã®ã¡ã½ãããå©ç¨ããã°ããã£ã¨ã·ã³ãã«ã«ããã¾ãã
after
<%= require 'date' def calendar(year, month) date = Date.new(year, month) cal = "<table>\n" cal << "<tr><th>æ¥</th><th>æ</th><th>ç«</th><th>æ°´</th><th>æ¨</th><th>é</th><th>å</th></tr>\n" cal << "<tr>" date.wday.times{cal << "<td />"} unless date.wday == 0 while date.month == month cal << "</tr>\n" << "<tr>" if date.wday == 0 cal << "<td>#{date.day}</td>" date = date.next end (6 - date.wday).times{cal << "<td />"} unless date.wday == 0 cal << "</tr>\n" cal << "</table>" cal end print calendar(2010, 12) %>
ã¾ã¨ã
ãããã£ã¦åããã«æ¸ãã¦ãã¾ãããèªåãã¾ã ã¾ã Rubyä¿®è¡ä¸ã§ãããã£ã¨è¯ãæ¸ãæ¹ããã£ã¨ããã¨æãã®ã§ãè¦ã¤ãããæãã¦ãã ããï¼ï¼
ã¶ã£ã¡ãã
ããããåéã§ã¯Javascriptã®æ¹ãç°¡åã ããµã¼ãã«è² è·ãããããªãã£ããã¨è¯ããã¨ã¥ããï¼
ã¿ããªJavascriptã使ããï¼
5åã§åãã JavaScript ãç¥ããªã人ã JavaScript ã®ä¾¿å©ããå¦ã¹ãè¨äºãæ¸ããã
http://d.hatena.ne.jp/ginpei/20101230/js_beginner