Ȼ/02

Top / Ȼ / 02

Ruby δñʥ: ȥ

Ruby Ȥϡ빽ɤǤƤ륹ץȸ졤ȤФΤ.
ȤꤢñʤȤñˤǤ롤ԥ塼ȻפäƤФ褤.
롤ʤƤӤˤϥԥå.

ʲޤϴñ˥ɤΤǡºݤưʤƤߤ褦.

ñʻȤ: ƤƤߤ褦

Ruby ǤϡץƥȥեȤƺơɤ߹Ȥ
ȤΤޤϴñ.
ǤΤ褦˥ɤ褦.

notes.png μ˽äơºݤˤäƤߤ褦.

  1. ޤ Ruby ưĶ ɬפ
    綵üǤϡcygwin UnixĶѤȤƻȤΤǡcygwin Ω夲褦
    ĤϰöΩ夲ȤޤǻȤäѤʤǹʤ.


  2. 줫Ȥǥ쥯ȥ(ե)褦
    줫ե뤬äꤷʤȤˤ褦
    ޤեܸ̾줬äƤ cygwin ȤƤݤʤȤˤʤΤǡ
    Ǥʤˤ褦


    warning.png ǰʤ顤ԥ塼ƥ󥰤ˤܸϡֻپפȤʤ뤳Ȥ. ȤϤʤ٤ե٥åȤǤ褦ĤƤ.


    ơcygwin κȥǥ쥯ȥ⤽˰פ褦
    Ūˤϡcygwin
     cd "եpathǤΥե̾"
    ȤФ褤


  3. ˥ƥȥǥΩ夲褦.
    windows ȥΡȥѥåɤǤ褤
    Emacs ȤȤͤ Meadow 褤͡

    warning.png ɤǥ˽ϤȡȸΨȤƤ⤯ʤ. 줫ΤȤͤȡɤǥפ֤Ȥϼ¤ϤȤƤפ. ֤ȤäĴ٤Ƥ.


  4. ƤΥץ񤳤
    ƥȥǥǼΤ褦˰Ԥ񤤤Ƥߤ褦.
     p 3+5
    warning.png ιԤ򤭤ȡֲԡפƤ! ԤƤʤԤǧ줺˥ץȤɤ߹ޤʤ⤷ʤ


  5. ä񤤤ץ̾Ĥ¸褦.
    ǥεǽǡsaveפȤ¸פ٤̾ĤƥեȤ¸Ǥ.
    ե̾Ϻ test.rb ȤƤ.


  6. ץưƤߤ褦
    cygwin ǡ
     ruby -w test.rb
    ǤäƤߤ褦. ޤ

    8

    Ȥ֤äƤ.


  7. ȤϤξ硤test.rb եȤŬ˽񤭴Ƥޤ
     ruby -w test.rb
    ȤƤߤ뤳Ȥ򷫤֤Ф󥸤Ǥ롥

ĶǤ Ruby ʸˡ

̾,ץ
ؤط׻Ԥʤ(1٤Ǥ褤)include Math
-pp Ȥν(1٤Ǥ褤)require 'pp'
ɽ1̤ƤФp ۤˤ
ɽ2p 긫䤹pp ۤˤ
ɽ3ǫɽprint ۤˤ
ѿ˿ʤɤa = 3.5
ݤ-a*b
٤-2**3 (8ˤʤ)
-a.abs (a )
ڤ夲-a.ceil (a ڤ夲)
ппlog(a)
ؿ-exp(a)
0ʾ1̤rand()
ѿ­-a += 1 (a 1­)
ѿ򥳥ԡ-a = b (a b Ȥ򥳥ԡ)
ʸ򥳥ԡʸϤüa = b.dup(a b Ȥ򥳥ԡ)
ʸDzʸs.length
ñʤ뽸-[a,b,3] ʤ
ǿ-group.size
1a[3] 4ܤǤؤ
ɲ-group.push(a)
, ǾȤκ, Ǿ[3,5,2].min ʤ
ʤ鷫֤롼פfor i in 1..5 do ۤˤ end
郎ʤưif ۤˤ then ۤ else ۤ2 end
⤷롼郎֤ϥ롼ưwhile ۤˤ do ۤ end
פƤ?Ӥa == b
ؿǤdef ۤˤ() end
ؿνϤؿǻȤreturn
ưΥѥ᡼ruby test.rb 3 10 ȤʤARGV[i] i+1
񤭤Ǥ# ۤˤ
ʸʸ϶̤
ѿ̾ʸǽ񤯤ѹԲ
ѿ $ ǻϤ

Ķñʥץ

ʿѤ׻Ƥߤ

οʿѤȤäƤߤ褦( 1.3 ˤʤϤ).
1.2 -3.0 3.3 4.1 0.9

ä񤷤르ꥺȤߤͤɬפϤʤ

­ơǿdz. 줫ɽ.

Ǥ.
notes.png ޤϡʬǥץȤǤߤ뤳Ȥ˥ȥ饤Ƥߤ褦.

㤨С(˾Ҳ𤷤ʸˡȤǤߤ)Τ褦ʥץबץȤƵ󤲤.

include Math

a = [1.2, -3.0, 3.3, 4.1, 0.9]

sum = 0.0
for i in 1..a.size do
  sum += a[i-1]
  end

average = sum/a.size

p average

ɤ. ʬǤޤǤ.

餯­פȤؼԤˤ񤷤äꤹ.
ѤäȤ狼ʤƤ褤顤Υץγʬ򤸤äߤʤɤơ

Ƥ뤫ʤȤʤǤ򤷤Ƥ

ʬ׻Ƥߤ

٤ϼοʬȤäƤߤ褦( 6.1 ˤʤϤ).
1.2 -3.0 3.3 4.1 0.9

notes.png ޤϡʬǥץȤǤߤ뤳Ȥ˥ȥ饤Ƥߤ褦.

ץץϤƺܤʤǤ.
ؼԤʬޤ׻Ǥ褦ʤ顤ֶڤϤ褤Ȼפ.

ݡ

ֵӹԤä½ˤĤơñˤޤȤ᤿򤻤.
Ƽ

  1. °(ز)
  2. ֹ
  3. ǯ
  4. ̾
  5. οΥݡ(θȤˤĤƵŤ)

񤯤Τ˺ʤ褦.

about Icons, ClipArts

Some icons in this page are downloadable at ICONFINDER.

The "note" icon notes.png designed by Marco Martin is distributed with the LGPL licence,
the "warning" icon warning.png designed by Alexandre Moore with the GPL licence
and the "triangle" icon JNorth_arrow-right-sm.png designed by Joseph North is distributed with the Creative Commons (Attribution-Noncommercial-Share Alike 3.0 Unported) licence.

Some clip arts used in this page are downloadable at Open Clip Art Library.
We deeply appreciate their superb works. With licence, they describe that "the actual clipart content on open clipart library is Public domain" in the web.