Ruby
rubyã®å ´åã¯ç¶ç¶ã®åã渡ãã«ãããã¯æ§æã使ãã¨ããæãã«æ¸ãããã ãªã åããéä¹ã®ä¾ã def fact(n) n==0 ? yield(1) : fact(n-1){|r|yield(n*r)} end fact(4){|r|puts r}
ä»ä½ã£ãfoo.dllãRubyããå¼ã³åºãã¦ã¿ã require 'dl/win32' puts Win32API.new('foo.dll','foo','i','i').call(1) s='Fizz' Win32API.new('foo.dll','bar','p').call(s) puts så®è¡çµæ 2 Buzzãã£ã¡ã¯ã¡ããã¨sã®å 容ãæ¸ãæãã£ãã
ä»ã¾ã§ã¯ããæ¸ãã¦ã foo = proc{|x,y|x+y}1.9ããã¯ããæ¸ãã foo = ->(x,y){x+y}ã¡ãªã¿ã«ããã§ã¯ãªãã®ã§æ³¨æ foo = ->{|x,y|x+y}å¼ã³åºãæ¹ãä»ã¾ã§ã¯ããæ¸ãã¦ã foo.call(1,2)1.9ããã¯ããæ¸ãã foo.(1,2)ãããæ¸ãã foo[1,2]ãããããã¯åºæ¥â¦
ãã°ããããruby1.9ã®Hashã¯JSON風ã«ãæ¸ããããã«ãªã£ã¦ãã ããã·ã¥çæã¯å¤ãã®å ´å以ä¸ã®ãããªãªãã©ã«(ããã·ã¥å¼)ã§è¡ããã¾ãã {a => b, ... } #aã¯ãã¼ãbã¯å¤ã¨ãªã {s: b , ... } #{ :s => b, ... } ã¨åãããã¼ãã·ã³ãã«ã®å ´åã®çç¥ããâ¦
Ruby1.9.0ãåºãã®ã§ã¡ãã£ã¨è©¦ãã¦ã¿ãã ã¯ãã¼ã¸ã£ irb> RUBY_VERSION => "1.9.0" irb> x = 100 => 100 irb> makeplus = lambda{|x| lambda{|y| x+y }} => #<Proc...> irb> plus1 = makeplus.call(1) => #<Proc...> irb> x => 100 #ä»ã¾ã§ã¯ãã㧠x ã 1 ã«ãªã£ã¦ãã irb></proc...></proc...>â¦
$stdout=StringIO.newã¨ããã¨ä¸è¦ãªãããã¡ãªã³ã°ããã¦ãã¾ãã $stdout=open('/dev/null','w')ã¨ããã¨OSä¾åã«ãªã£ã¦ãã¾ãã $stdout, $stderr ã«è¨å®ããããªãã¸ã§ã¯ãã«ã¯ write ã¨ããåã® ã¡ã½ãããå®ç¾©ããã¦ããå¿ è¦ãããã¾ãã http://www.râ¦
欲ããã¡ã½ãããæ¨æ¸¬ããguessã¨ããã¡ã½ãããä½ã£ã¦ã¿ãã 使ãæ¹ å ã®å¤.guess(ç®çã®å¤,å¼æ°â¦) irb> require 'guess' => true irb> 1.guess 2 â 1ãã2ã«ãªãã¡ã½ãããæ¢ã => ["next", "succ"] irb> [1,2,3].guess 3 â [1,2,3]ãã3ãè¿ãã¡ã½ãããâ¦
irb> (0..9).sort_by{rand} => [2, 3, 4, 5, 7, 8, 9, 1, 0, 6]ããã¯ãã¾ããæåããã http://d.hatena.ne.jp/dropdb/20071109/1194535114
|matz> ãããç§ãã§ãã諸è¬ã®äºæ ã§nilã¨falseãåé¢ããã¨ãã«ã¯ç¸å½ |matz> æ°æã¡æªãã£ãã§ããä»æãã°ããããããªãã£ãã¨æããã©ã | |nil 㨠false ãåé¢ããäºæ ã£ã¦ã©ãããç©ã ã£ããã§ããï¼ä»å話é¡ã«ããªã£ã¦ããHashã®æªå®ç¾©å¤ã¨ã®ããâ¦
matrix.rbã®éè¡åè¨ç®ã£ã¦ãªãããããããï¼ irb(main):001:0> require 'matrix' => true irb(main):002:0> Matrix[[2,1],[3,1]].inv ExceptionForMatrix::ErrNotRegular: Not Regular Matrix from /usr/lib/ruby/1.8/matrix.rb:595:in `inverse_from' froâ¦
ã¾ãã/usr/lib/ruby/1.8ã®ä¸ãè¦ã¦ã¿ãã % find /usr/lib/ruby/1.8 -name '*numerable*' -printç¹ã«Enumerable.rbã£ã¦ãã¡ã¤ã«ã¯ãªãã ããèããããrequire 'Enumerable'ã£ã¦ãããããããªãã¦ãinclude Enumerableã£ã¦ãã£ã¦ããã ã£ãã ããããå®â¦
rubyã®ãããã¬ãã«ï¼ï¼ï¼ã®selfã¯mainã¨ãããªãã¸ã§ã¯ãã ã£ãã % ruby -e 'p self' mainirbã§ãåãmainã«ãªã£ã¦ãã ãªããã®ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã£ã¦ãããããªãã¦ç´ ã®Objectãªããã ã % irb irb(main):001:0> self => main irb(main):002:0> self.â¦
ãããæãã¦ããã£ãã % ruby -e '" ".upto("~"){|s|puts s}'âè¨æ£ï¼åºåçµæã確èªãã¦ãªãã£ãããããä¸ã¨åãã§9ã§æ¢ã¾ã£ã¦ãã¾ããuptoã¯ãããã¯ãå¿ é ãè¿å¤ã¯èªåã®ã¿ã > " ".upto("~").to_a LocalJumpError: no block given > " ".upto("~"){|s|â¦
% ruby -Ku -e 'puts "ããã".length' 9 % ruby -Ku -rjcode -e 'puts "ããã".jlength' 3 % ruby -Ku -e 'puts "ããã".split("").length' 3è¦æ¸: $KCODE ã®å½±é¿ã¯ã»ã¨ãã©ã®å ´å String ããã Regexp ã«å¯¾ãã¦ã ãShift_JIS ã® 2 ãã¤ãç®ã« \ ãå«ã¾â¦
ããã¯ãããä»ã¾ã§javascriptã§ãããã¨ããã¨é»ã¾ãã¦ãããã¡ã¤ã³è¶ãã®ãã©ã¦ã¶æä½ãããã§åºæ¥ããRubyã§ã¦ã§ããµã¤ãã®ã¢ã¯ã»ã¹ãèªååããã©ã¤ãã©ãªãWWW::Mechanizeãã®æ¥æ¬èªãªãã¡ã¬ã³ã¹ã§ããjavascriptã®å¦çãå ¥ã£ã¦ãã¦ãã¤ãã¦ããããï¼â¦