2008-07-01ãã1ã¶æéã®è¨äºä¸è¦§
Needleã®ã¤ã³ã¿ã¼ã»ãã¿ã¯ãããã·æ¹å¼ã§ããã¬ã¸ã¹ããªã«ç»é²ããã¤ã³ã¹ã¿ã³ã¹ããèªèº«ã®ã¡ã½ãããå¼ã³åºããå ´åãã¤ã³ã¿ã¼ã»ãã¿ã¯ä½åãã¾ããã require 'rubygems' require 'needle' # ã¬ã¸ã¹ããªã«ç»é²ãããµã¼ãã¹ã¯ã©ã¹ class Kitten def initialiâ¦
ä»»æã®é·ãã®æååãè¿ãå¼ãããã£ã¨ä½æãããã ãã®1 String str = new StringBuilder() {{ for(int i=0;i<100;i++) append("a"); }}.toString(); ã§ãããã§ã§ããªããfinalã§ãããããã§ããã ãã®2 String str = new String( Arrays.fill( new chaâ¦
ä»æ¥è¦ã¤ãããªãã®ã³ã¼ãã singleton = class << service; self; end serviceã¯ä»»æã®ãªãã¸ã§ã¯ããã©ããããã§ãserviceã®ç¹ç°ã¯ã©ã¹ãåãåºãã¦ãããããã åãåºããã¯ã©ã¹ã¯ãã¯ã©ã¹ãªã®ã§ããinstance_methodsãã§ã¡ã½ããä¸è¦§ãåå¾ãããããdâ¦
ç°¡åãªã¢ãã«ã¯ã©ã¹(Javaã«ãããJavaBeançãªã¢ã)ãä½ãããå ´åãStructã便å©ã§ãã # æ§é ä½ã¯ã©ã¹ã®ä½æ Kitten = Struct.new(:age, :name) # æ§é ä½ãªãã¸ã§ã¯ãã®ä½æ mii = Kitten.new( 1, "mii" ) # å±æ§ã®åç § puts mii.name puts mii.age # å±æ§â¦
Needleã®ã¤ã³ã¿ã¼ã»ãã¿æ©è½ã使ã£ã¦ã¿ã¾ãã Seasarãªã©ã§æä¾ããã¦ããã¡ã½ããã¤ã³ã¿ã¼ã»ãã¿ã®æ©è½ãå©ç¨ã§ãã¾ãã å°ç¨ã®ã¤ã³ã¿ã¼ã»ãã¿ã¯ã©ã¹ãç¨æãã¦é©ç¨ããã»ãããããã¯ã使ã£ã¦ç°¡åã«ããã¯å¦çãæå®ãããã¨ãå¯è½ã§ãã ãããã¯ã使ã£ãâ¦
ãNeedleãã¯Rubyã§ä½¿ããDIã³ã³ããã§ãã ã¤ã³ã¹ã¿ã³ã¹ã®ã©ã¤ããµã¤ã¯ã«ç®¡çããã¤ã³ã¸ã§ã¯ã·ã§ã³ãªã©ã®DIã³ã³ããã®åºæ¬çãªæ©è½ããµãã¼ãã è¨å®ãã¡ã¤ã«ãå©ç¨ãããããã°ã©ã ä¸ã§ãµã¼ãã¹ãç»é²ããæ¹å¼ãæ¡ç¨ããã¦ãã¾ããGuiceã©ã¤ã¯ã AOPæ©è½ãâ¦
ãããªæãã§æ¸ãã¦ã¿ãã var datas = Array(9,3,5,7) // æ大 println( "max:" + datas.reduceLeft( (max,i) => i max max ) ) // æå° println( "min:" + datas.reduceLeft( (min,i) => i min min ) ) // å¹³å println( "avg:" + datas.reduceLeft( (sum,â¦
ãBy-Name Parametersãã使ãã¨ã foo { println("aaaa") } ã¿ãããªæãã§å¼ã³åºããé¢æ°ãä½æã§ãã¾ããé¢æ°fooã®å®ç¾©ã¯ä»¥ä¸ã®ãããªæãã def foo[R]( proc: => R ):R = { try { println("before...") proc // å¼æ°ã®procãè©ä¾¡ãã¦å®è¡ } finally { pâ¦
次ã®ãããªEnumerableãincludeããã¯ã©ã¹ããã£ã¦ã class Foo include Enumerable def each ["a","b","c"].each{|i| yield i } # ãã¡ãããããªå®è£ ãããªãã end end ããã®Enumerable#mapã®ãããã¯ä¸ã§ãç¾å¨ã®è¦ç´ ã®ã¤ã³ããã¯ã¹ãå¿ è¦ã«ãªã£ãã®ã§â¦
ãã¿ããªãã®ã§æè¿(ã¨ãã£ã¦ããã2ã¶æãããã§)èªãã æ¬ã§ã並ã¹ã¦ã¿ã¾ãã ââââ è¥è ã¯ãªã3å¹´ã§è¾ããã®ã? å¹´ååºåã奪ãæ¥æ¬ã®æªæ¥ (å æ社æ°æ¸)ä½è : åç¹å¹¸åºç社/ã¡ã¼ã«ã¼: å æ社çºå£²æ¥: 2006/09/15ã¡ãã£ã¢: æ°æ¸è³¼å ¥: 17人 ã¯ãªãã¯: 447åãâ¦
JSON-RPCã©ã¤ãã©ãªã®Orbjsonã§ã¯WEBrickã®Servletãæä¾ããã¦ãã¾ããããã使ãã¨JSON-RPCã§ã¢ã¯ã»ã¹ã§ããWebãµã¼ãã¹ãããã£ã¨ä½æã§ãã¾ããã¨ãããã¨ã§ãç°¡åã«ã§ããæé ãã¾ã¨ãã¦ã¿ã¾ãã æ¦è¦ Orbjsonã®ã¤ã³ã¹ãã¼ã« æä¾ããAPIãå®ç¾©ãããµã¼â¦
Rubyæ¨æºæ·»ä»ã®WEBrickã§HTTPãµã¼ãã¬ãããä½ã£ã¦ã¿ã¾ãããã¾ãã¯HelloWorldãWEBrickã®ãµã¤ãã«ãããµã³ãã«ã®ã³ããã§ãã require 'webrick' include WEBrick # httpãµã¼ãã¼ s = HTTPServer.new( :Port => 8080 ) # ãµã¼ãã¬ãã class HelloServlet <â¦
ãã®ããã ä½æãããã¯ã¦ãªããã¯ãã¼ã¯ ããã³ãã¨ã³ããã«æ¤ç´¢çµæ詳細ã®è¡¨ç¤º/é表示ãåãæ¿ããæ©è½ã追å ãâ ã¯ã¦ãªããã¯ãã¼ã¯ ããã³ãã¨ã³ãã®æ°ããã¤ããè©¦ä½ åãæ¿ãã®ãªã³ã¯ã¯ã¨ãããããããé¨åã«é ç½®ã è¨å®å¤ã¯ã¯ããã¼ã§è¦ããããã«ãâ¦
404 java-ja ãªããã¼ - AOPã©ãã§ä½¿ãï¼ãèªãã§ãç¾å¨é¢ãã£ã¦ããããã¸ã§ã¯ãã§ã®AOPã®ä½¿ãã©ããã«ã¤ãã¦ã¾ã¨ãã¦ã¿ã¾ãã 使ã£ã¦ããã¨ãã ãã©ã³ã¶ã¯ã·ã§ã³ ãã°(ã¨ã©ã¼ãã°/æ§è½ãã°/æä½ãã°) èªè¨¼ãã§ã㯠ãã£ãã·ã¥ DBã¢ã¯ã»ã¹ã®çµæããã¡ã¤ã«â¦
NodeSeq#\ãNodeSeq#\\ã§éãã§ã¿ãã // XML ãªãã©ã« var xml:scala.xml.Elem = <kittens type="animal" xmlns="http://kittens.com" xmlns:t="http://tigers.com"> <kitten age="1">mii</kitten> <t:tiger age="2">tora</t:tiger> <kitten age="3">shiro</kitten> <foo> <kitten age="3">kuro</kitten> </foo> </kittens> // ã«ã¼ãç´ä¸ã®kâ¦
XMLãªãã©ã«ã¨ãããã¾ãã // XML ãªãã©ã« var xml:scala.xml.Elem = <kittens xmlns="http://kittens.com"> <kitten>mii</kitten> <kitten>tora</kitten> <kitten>shiro</kitten> </kittens> // kittens/kittenè¦ç´ ãæ¢ãã¦ãã¦ãã®ããã¹ãã表示ããã // -filterã®ã¨ããã¯ãNode.xmlTypeãã使ãã®ããããã // -ãNode.\ãã§ãã£ã¨ã·ã³ãã«ã«ãããããâ¦
calicoãããããæ¨è«ãããåãã©ã¡ã¼ã¿ããClassãå¾ãã®ã³ã¼ãã«ã¤ãã¦ãææãé ããã®ã§(ãããã¨ããããã¾ã!)ãããããã¨æ¤è¨¼ãã¦ã¿ããçµè«ã¨ãã¦ã¯ãä¸è¨æ¥è¨ã®ã³ã¼ãã¯Eclipseã®ã³ã³ãã¤ã©ã§ã³ã³ãã¤ã«ããã¯ã©ã¹ã§ããæå¾ éãã®åä½ã¨ãªããªãâ¦
SAXTransformerFactory#newTransformerHandler() ã使ãã¨ãSAXã§XMLãèªã¿ã¤ã¤ãã®ã³ãã¼ãã¹ããªã¼ã ã«æ¸ãåºããã¨ãã§ãã¾ããå§è²ãªã©ãé§ä½¿ãã¦ã«ã¹ã¿ãã¤ãºããã°ãç¹å®ã®è¦ç´ ãé¤ããXMLã®ã³ãã¼ãä½æããã¨ãã£ããã¨ãå¯è½ãDOMã«ãã¦ããã·ãªã¢â¦
ãã§ãã¯ããã¯ã¹ãã©ã¸ãªãã¿ã³ã«èª¬æç¨æååãè¨å®ããå ´åããlabelãè¦ç´ ã使ç¨ãã¾ãã æ®éã«ããã¹ããé ç½®ãã¦ãè¦ãç®ä¸ã¯åãã§ãããlabelã§é¢é£ä»ããæååãæå®ããã¨ãæååãã¯ãªãã¯ããå ´åããã§ãã¯ããã¯ã¹ãã©ã¸ãªãã¿ã³ã®on/offãâ¦
statusã¨Locationããããæå®ããã°OKã #!/usr/local/bin/ruby -- require "cgi" cgi = CGI.new print cgi.header( { "status" => "REDIRECT", "Location" => "http://d.hatena.ne.jp/unageanu/" }) cgiã«ã¢ã¯ã»ã¹ããã¨ä»¥ä¸ãè¿ããã HTTP/1.1 302 Foundâ¦
ã¯ã©ã¹ãTraitã«ã def unary_<æ¼ç®å(- or + or ! or ~)> = ... ã®ãããªã¡ã½ãããå®ç¾©ãã¦ããã¨ã <æ¼ç®å> <ã¬ã·ã¼ã> ã®å½¢å¼ã§ã¡ã½ãããå¼ã³åºããã¨ãã§ãã¾ãã // ãã¹ãç¨ã¯ã©ã¹ class Foo( value:Int ) { override def toString = value.toStrinâ¦
æ¨æ¥ä½æããhpricotçfaviconã®URIãæ¢ãã¯ã©ã¹ãsakuraã®ã¬ã³ã¿ã«ãµã¼ãã¼ã«ã¢ãããã¼ããããã¨ç»çããããhpricotã®ã¤ã³ã¹ãã¼ã«ã§ã¯ã¾ããhpricotã¯ãã¤ããªã®å ±æã©ã¤ãã©ãªã使ç¨ãã¦ãããããgemã使ã£ã¦sakuraã®ãµã¼ãã¼ã§ã³ã³ãã¤ã«ãã¦ã¤ã³ã¹â¦
favicon.iconã®URIãæ¢ãã¯ã©ã¹ãæ¸ãããWikipedia-Faviconããã head/link[@rel='shortcut icon'] head/link[@rel='icon'] ã«ã¼ããã£ã¬ã¯ããªã®favicon.icon ã®ãã¡æåã«è¦ã¤ãã£ãã¢ããè¿ãã require 'rubygems' require 'hpricot' require 'httpcliâ¦
ã¯ã¦ãªããã¯ãã¼ã¯ ããã³ãã¨ã³ãã®æ°ããã¤ããä½ã£ã¦ã¿ãã æ¦ç¥ ãç»é²ç´å¾ã®ããã¯ãã¼ã¯ããç¹å®ã®ãã使ãããã¯ãã¼ã¯ãã«ç´ æ©ãã¢ã¯ã»ã¹ããæ段ãæä¾ å人çã«ã¢ã¯ã»ã¹ããé »åº¦ã®é«ã以ä¸ã®äºã¤ã«ã¤ãã¦ãå°ç¨ã®ã«ãã´ãªãç¨æãç´ æ©ãã¢ã¯ã»ã¹â¦
æè¿æ°ä»ããã®ã ãã©ãscalaã®ä¸çã«ããScala Bazaarsãã¨ããããã±ã¼ã¸ç®¡çã®ä»çµã¿(rubyã®RubyGemsçãªã¢ã)ãããã¾ãããsbazãã¨ãããã¼ã«ãæä¾ããã¦ãã¦ãããã使ã£ã¦ããã±ã¼ã¸ã®è¿½å /åé¤ãå¯è½ãåºæ¬çãªä½¿ãæ¹ã¯æ¬¡ã®éãã§ãã # ã¤ã³ã¹ãâ¦
<span class="x"><a href="#">ãã¹ã </a></span> ã¿ãããªæãã®aè¦ç´ ããã£ã¦ã ãªã³ã¯ã®è²ãæå®ã®è²ã«ãã¦ã ãã¦ã¹ãªã¼ãã¼æã«ã®ã¿ã¢ã³ãã¼ã©ã¤ã³ãå¼ã ããã«ãããã¨æãã次ã®ãããªCSSãæ¸ãã¦ããã®ã ããã©ãIE6ã ã¨æå¾ éãã®åä½ã¨ãªããªãã(FireFox2ã ã¨æ£ããåä½ãã)ã span.x {â¦
ã¯ã¦ãªããã¯ãã¼ã¯ä»¶æ°åå¾APIã使ã£ã¦åå¾ã§ãã¾ããXMLRPCã使ã£ã¦ããã£ã¨ã¢ã¯ã»ã¹ã require 'xmlrpc/client' client = XMLRPC::Client.new2("http://b.hatena.ne.jp/xmlrpc") result = client.call("bookmark.getCount", "http://d.hatena.ne.jp/", # â¦
以ä¸ã®è¨å®ãpom.xmlã«æ¸ãã¦ããã¨ããmvn installãã¨ãã§ãã¹ãç¨ã®ã¯ã©ã¹(ãsrc/testã以ä¸ã®ã½ã¼ã¹)ãåºããjarãä½æãããdeployãããããã«ãªãã¾ãã <project> ... <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <executions> <execution> <goals> <goal>test-jar</goal> </goals> </execution> </executions></plugin></plugins></project>
Specsã¯ãScalaã§ä½¿ããBDDãªãã¹ãã£ã³ã°ãã¬ã¼ã ã¯ã¼ã¯ã§ããJUnit4ã¢ããã¿ãæä¾ããã¦ãããMavenã«çµã¿è¾¼ãã§ä½¿ããã¨ãå¯è½!ã¨ãããã¨ã§ãMavenãªJavaããã¸ã§ã¯ãã®ãã¹ããScala+Specsã§æ¸ãæé ãã¾ã¨ãã¦ã¿ã¾ãã ã¨ãã£ã¦ãåºæ¬çã«ã¯ã pom.xmâ¦