ä»ã®è¨èªã«æ £ãã人ãRubyã使ã£ãã¨ãã«ã¤ã¾ãããã¡ãª9ã¤ã®ãã¤ã³ã
ä»ã®è¨èªã«æ
£ãã人ãPythonã使ã£ãã¨ãã«ã¤ã¾ãããã¡ãª9ã¤ã®ãã¤ã³ãã®ç¶ç·¨ãããã ãããæ¸ãã¦ãã¾ã see: ã ãããã¼
0ã¯ç, 空æååãç
Cè¨èªãªã©ã¨éã£ã¦ã0ã¯å½ã§ã¯ãªããPythonãJavaScript, PHPã¨éã£ã¦ç©ºæååãå½ã§ã¯ãªãã
>if 0 then print "true!\n" end true! > if "" then print "true!\n" end (irb):1: warning: string literal in condition true!
æ¬å¼§ããªãã¦ã0å¼æ°ã§ã®é¢æ°å¼ã³åºããèµ·ãã
PythonãJavaScriptã§ã¯å¼ä¸ã«ç¾ããé¢æ°åã¯é¢æ°ãæãããããRubyã§ã¯0å¼æ°ã§ã®å¼ã³åºããè¡ãããã
# Python >>> def foo(): print "foo!" ... >>> foo <function foo at 0x100445f50>
# Ruby > def foo() print "foo!\n" end => nil > foo # ã¡ã½ããå¼ã³åºããèµ·ãã foo! => nil
å¤æ°ã¯ãã¹ã¦åç §
> a = [] > b = a > b << 1 > a => [1]
ã½ã¼ã¹ã³ã¼ãã®ã¨ã³ã³ã¼ãã£ã³ã°
Ruby1.9ã§ã¯ã½ã¼ã¹ã³ã¼ãã®ã¨ã³ã³ã¼ãã£ã³ã°ãæå®ããã«ã½ã¼ã¹ã³ã¼ãä¸ã§ASCII以å¤ã®æåã使ãã¨ã·ã³ã¿ãã¯ã¹ã¨ã©ã¼ã«ãªãã
$ cat > t.rb p "ã»ã" $ ruby1.9 t.rb t.rb:1: invalid multibyte char (US-ASCII) t.rb:1: invalid multibyte char (US-ASCII)
PythonãSchemeåæ§ã®æ¹æ³ã§ã½ã¼ã¹ã³ã¼ãã®ã¨ã³ã³ã¼ãã£ã³ã°ãæå®ã§ããã詳ãããã¨ã¯ãã¡ãï¼å¤è¨èªå
# -*- coding: utf-8 -*- p "ã»ã"
1.8ã§ä¸è¨ã®ãããªã³ã¼ããSJISã§æ¸ãã¨æ§æã¨ã©ã¼(unterminated string meets end of file)ã«ãªããrubyèµ·åæã®ãªãã·ã§ã³ã«-Ksãæå®ããå¿ è¦ãããã
print "æ©è½"
JISè¦æ ¼ã«æºæ ããå¦çç³»ããã½ã¼ã¹ã³ã¼ãã«US-ASCII以å¤ã®æåãå ¥ã£ã¦ããå ´åã«ã©ãããæåããããã¯æªè¦å®ã§ããã
æ´æ°ããªã¼ãã¼ããã¼ããªã
æ´æ°ã®å æ¸ä¹é¤ãã·ããæ¼ç®ã§æ´æ°(Fixnum)ã®ç¯å²ãè¶ ããå ´åãCãªã©ã®ããã«ããµããããããæ¨ã¦ã¦ç¯å²å ã«åããã®ã§ã¯ãªããä¸éã®ãªãBignumã«å¤æããããããã¦æåå表示ãè¦ã¦ãåºå¥ãã¤ãã«ããã
> x = -4611686018427387904 > x.class => Fixnum > x /= -1 => 4611686018427387904 > x.class => Bignum
Cã§æ¸ãããã¢ã«ã´ãªãºã ãéèªè¨³ãããããã¨ãããªãæ°ã¥ãã«ãããã°ãå ¥ã£ã¦ãã¾ãã
ååã®ã¯ã©ã¹å®ç¾©ããã£ãå ´åãè¡çªããã«åæããã
class Foo def x; 1 end end class Foo def y; 2 end end p Foo.new.x #=> 1 ã¨è¡¨ç¤ºããã p Foo.new.y #=> 2 ã¨è¡¨ç¤ºããã
å ´åã«ãã£ã¦ã¯ä¾¿å©ã«ä½¿ããã±ã¼ã¹ãããããç¥ããªããã½ã¼ã¹ã³ã¼ããèªã人ãæå³çã«åæããã¦ãããã¨ãç¥ããªãã¨æ··ä¹±ãããã§ã¯ããã