Ruby$B%3!<%G%#%s%05,Ls(B

$B$O$8$a$K(B

$BK\J8=q$O!"(BRuby$B$K$h$j%3!<%G%#%s%0$r9T$&:]$N5,Ls$K$D$$$F=R$Y$k!#(B $B)$9$k!#(B

$B%=!<%9%3!<%I$N@07A(B

$B%$%s%G%s%H(B

$B%W%m%0%i%`$rFI$_$d$9$/$9$k$?$a!"%$%s%G%s%H$rE,599T$&!#%$%s%G%s%H(B $BI}$O(B2$B$H$9$k!#$^$?!"%$%s%G%s%H$K$O%9%Z!<%9$N$_$r;HMQ$7!"%?%V$O;HMQ(B $B$7$J$$!#(B($B4D6-$K$h$j%?%VI}$,0[$J$k$?$a!#(B)

$BNc(B:

if x > 0
  if y > 0
    puts "x > 0 && y > 0"
  end
end

$B0l9T$N7e?t(B

$B0l9T$N7e?t$O:GBg(B80$B7e$^$G$H$9$k!#(B

$B6u9T(B

$BJ#?t$N%/%i%9$N6h@Z$K$O6u9T$rA^F~$9$k!#(B

$BNc(B:

class Foo
  ...
end

class Bar
  ...
end

$B8m$C$?Nc(B:

class Foo
  ...
end
class Bar
  ...
end

$B$^$?!"%/%i%[email protected]$N6h@Z$K$b6u9T$rA^F~$9$k!#(B $B$?$@$7!":[email protected]$NA0$d!":[email protected]$N8e$K$O6u9T$OA^F~$7(B $B$J$$!#(B

$BNc(B:

class Foo
  attr :bar

  def baz
    ...
  end

  def quux
    ..
  end
end

$B8m$C$?Nc(B:

class Foo

  attr :bar

  def baz
    ...
  end

  def quux
    ...
  end

end

$B%3%a%s%H(B

$B%a%=%C%IDj5A$NCf$K$O%3%a%s%H$O5-=R$7$J$$!#(B($B%3%a%s%H$,I,MW$@$H;W$o(B $B$l$k$h$&$J%3!<%I$K$O%j%U%!%/%?%j%s%0$r9T$&!#(B)

$B$?$@$7!"%/%i%9!&%b%8%e!<%k$d%Q%V%j%C%/$J%a%=%C%I$K$O;EMM$r(BRDoc$B%9(B $B%?%$%k$G5-=R$9$k!#(B

$BNc(B:

# $B%3%s%^6h@Z$NJ8;zNs(B+str+$B$rJ,3d$7!"7k2L$rG[Ns$K$7$FJV$9!#(B
def split_csv(str)
  return str.split(/,/)
end

$B9=J8$K4X$9$k5,Ls(B

$B%/%i%[email protected](B

$B%/%i%[email protected]$O0J2<$N=g=x$G5-=R$9$k!#(B

  1. $B%b%8%e!<%k$N%$%s%/%k!<%I(B
  2. $BDj?t$NDj5A(B
  3. $B%/%i%9JQ?t!&%/%i%9$N%$%s%9%?%s%9JQ?t$NDj5A(B
  4. $B%Q%V%j%C%/$J%/%i%9%a%=%C%I$NDj5A(B
  5. $B%"%/%;%5$NDj5A(B
  6. initialize$B$NDj5A(B
  7. $B%Q%V%j%C%/$J%$%s%9%?%s%9%a%=%C%I$NDj5A(B
  8. $B%W%m%F%/%F%#%C%I$J%/%i%9%a%=%C%I$NDj5A(B
  9. $B%W%m%F%/%F%#%C%I$J%"%/%;%5$NDj5A(B
  10. $B%W%m%F%/%F%#%C%I$J%$%s%9%?%s%9%a%=%C%I$NDj5A(B
  11. $B%W%i%$%Y!<%H$J%/%i%9%a%=%C%I$NDj5A(B
  12. $B%W%i%$%Y!<%H$J%"%/%;%5$NDj5A(B
  13. $B%W%i%$%Y!<%H$J%$%s%9%?%s%9%a%=%C%I$NDj5A(B
  14. $B%M%9%H$7$?%/%i%9$NDj5A(B

$B%"%/%;%5$NDj5A(B

$B%"%/%;%5$NDj5A$K$O!"(Battr_accessor$B!&(Battr_reader$B!&(B attr_writer$B$r;HMQ$9$k!#(B(attr$B$O;HMQ$7$J$$!#(B)

$B%a%=%C%I$NDj5A(B

$B%a%=%C%IDj5A$N2>0z?t%j%9%H$K$O3g8L$rIU$1$k!#(B $B$?$@$7!"0z?t$,$J$$>l9g$O!"3g8L$r>JN,$9$k!#(B

$BNc(B:

def foo(x, y)
  ...
end

def foo
  ...
end

$B8m$C$?Nc(B:

def foo x, y
  ...
end

def foo()
  ...
end

$B%/%i%9%a%=%C%I$NDj5A(B

$B%/%i%9%a%=%C%I$NDj5A$K$O(Bself$B$r;HMQ$9$k!#(B

$BNc(B:

class Foo
  def self.foo
    ...
  end
end

$B8m$C$?Nc(B:

class Foo
  def Foo.foo
    ...
  end
end

$B%a%=%C%I8F$S=P$7(B

$B%a%=%C%I8F$S=P$7$N0z?t%j%9%H$K$O3g8L$rIU$1$k!#$?$@$7!"0z?t$,$J$$(B $B>l9g$O!"3g8L$r>JN,$9$k!#$^$?!"(Bprint$B$d(Bputs$B$d(Bp$B$N(B $B>l9g$O!"0z?t$N3g8L$r>JN,$7$F$b$h$$!#(B

$BNc(B:

foo(1, "abc")
obj.foo(1, "abc")
bar
print "x = ", x, "\n"

$B8m$C$?Nc(B:

foo 1, "abc"
obj.foo 1, "abc"
bar()

$B%V%m%C%/(B

$B%V%m%C%/$O4pK\E*$K(Bdo ... end$B$r;HMQ$9$k!#(B

$BNc(B:

foo(x, y) do
  ...
end

x = bar(y, z) do
  ...
end

$B8m$C$?Nc(B:

foo(x, y) {
  ...
}

x = bar(y, z) {
  ...
}

$B$?$@$7!"%a%=%C%I%A%'%$%s$r9T$&>l9g$O(B{ ... }$B$r;HMQ$9$k!#(B

$BNc(B:

s = ary.collect { |i| i.to_s }.join(",")

$B8m$C$?Nc(B:

s = ary.collect do |i| i.to_s end.join(",")

return

$B%a%=%C%I$NCM$rJV$9>l9g$O!"I,$:(Breturn$B$r;HMQ$9$k!#(B $B$^$?!"(Breturn$B$N3g8L$O>JN,$9$k!#(B

$BNc(B:

def add(x, y)
  return x + y
end

$B8m$C$?Nc(B:

def add(x, y)
  x + y
end

def add(x, y)
  return(x + y)
end

yield

yield$B$N8F$S=P$7J}K!$O%a%=%C%I8F$S=P$7$K=`$:$k!#(B

$B>r7oJ,4t(B

if$B<0$N(Bthen$B$O>JN,$9$k!#$^$?!"(Bif !x$B$N$h$&$J>l9g$O!"(B unless x$B$KCV$-49$($k!#$?$@$7!"(Bunless$B$N>l9g!"(B else$B$O;HMQ$7$J$$!#$^$?!">r7o$,==J,$K4JC1$G!"0l9T$G=q$1$k>l(B $B9g$O!"(Bif/while$B=$>~;R$r;HMQ$7$F$b$h$$!#(B

$BNc(B:

if x > 0
  puts "x > 0"
else
  puts "x <= 0"
end

unless x
  puts "x is false"
end

puts "x is true" if x

$B8m$C$?Nc(B:

if x > 0 then
  puts "x > 0"
end

unless x
  puts "x is false"
else
  puts "x is true"
end

puts "foo && bar && baz && quux" if foo &&
  bar && baz && quux

case$B$r;HMQ$G$-$k>l9g$O!"(Bcase$B$r;HMQ$9$k!#(B $B$^$?!"(Bthen$B$O>JN,$9$k!#(B

$BNc(B:

case x
when 1
  ...
when 2
  ...
end

$B8m$C$?Nc(B:

if x == 1
  ...
elsif x == 2
  ...
end

case x
when 1 then
  ...
when 2 then
  ...
end

$B>r7oJ,4t$N<0$NCM$O;HMQ$7$J$$!#(B

$BNc(B:

if x > 0
  msg = "x > 0"
else
  msg = "x <= 0"
end

$B8m$C$?Nc(B:

msg = if x > 0
        "x > 0"
      else
        "x <= 0"
      end

$B7+$jJV$7(B

while$B$N(Bdo$B$O>JN,$9$k!#$^$?!"(Bwhile !x$B$N$h$&$J>l9g$O!"(B until x$B$KCV$-49$($k!#(B

$BNc(B:

while cond
  ...
end

until cond
  ...
end

$B8m$C$?Nc(B:

while cond do
  ...
end

$B$^$?!"L58B%k!<%W$K$O(Bloop$B$r;HMQ$9$k!#(B

$BNc(B:

loop do
  ...
end

$B8m$C$?Nc(B:

while true
  ...
end

$BO@M}1i;;;R(B

$BO@M}1i;;$K$O(B!$B$d(B&&$B$d(B||$B$r;HMQ$9$k!#(B (not/and/or$B$O;HMQ$7$J$$!#(B)

$B;09`1i;;;R(B

$BL@$i$+$K2DFI@-$KLdBj$,$J$$>l9g$r=|$$$F!";09`1i;;;R$O$J$k$Y$/;HMQ$7$J$$!#(B $B$H$/$K!"3g8L$,I,MW$J$[$I>r7o$,J#;($J>l9g$d!"J#?t9T$K$J$C$F$7$^$&(B $B>l9g$O!";09`1i;;;R$O;HMQ$7$J$$!#(B

$BJ8;zNs%j%F%i%k(B

$BJ8;zNs%j%F%i%k$K$O4pK\E*$K(B"..."$B$r;HMQ$9$k!#$?$@$7!"FCl9g$N$_!"(B'...'$B$r;HMQ$9$k!#(B $B$^$?!"86B'E*$K%R%"%I%-%e%a%s%H$O;HMQ$7$J$$!#(B

$BL?L>5,Ls(B

$BA4HL(B

  1. $B86B'$H$7$F!"C18l$N>JN,$O9T$o$J$$!#(B
  2. $B%9%3!<%W$,69$$%k!<%WJQ?t$K$O!"(Bi, j, k$B$H$$$&L>A0$r$3$N=g=x$G;H(B $BMQ$9$k!#(B
  3. $B%9%3!<%W$,69$$JQ?tL>$K$O!"%/%i%9L>$r>JN,$7$?$b$N$r;HMQ$7$F$h$$!#(B ($BNc(B: eo = ExampleObject.new)

$B%/%i%9!&%b%8%e!<%kL>(B

$B%/%i%9!&%b%8%e!<%kL>$O!"3FC18l$N0lJ8;zL\$rBgJ8;z$K$7!"(B`_'$B$J$I$N6h@Z(B $BJ8;z$O;HMQ$7$J$$!#(B $B$?$@$7!"(BHTTP$B$J$I$NN,8l$N>l9g$O$9$Y$FBgJ8;z$N$^$^$H$9$k!#(B

$BNc(B:

ExampleClass  
HTTPClient

$B8m$C$?Nc(B:

Example_Class
EXAMPLE_CLASS
HttpClient
HTTPclient
HTTP_Client

$B%a%=%C%IL>(B

$B%a%=%C%IL>$O!"$9$Y$F>.J8;z$H$7!"C18l$N6h@Z$j$K(B`_'$B$rMQ$$$k!#%a%=%C(B $B%IL>$K$OF0;l$N867A$r;HMQ$9$k!#(B

$BNc(B:

add_something

$B8m$C$?Nc(B:

addsSomething
Add_Something

$B??56CM$rJV$9%a%=%C%IL>$O!"F0;l$^$?$O7AMF;l$K(B`?'$B$rIU$1!"7AMF;l$K(B `is_'$B$OIU$1$J$$!#(B

$BNc(B:

visible?

$B8m$C$?Nc(B:

is_visible
is_visible?

$B$^$?!"GK2uE*$J%a%=%C%I$HHsGK2uE*$J%a%=%C%I$NN>J}$rDs6!$9$k>l9g!"GK(B $B2uE*$J%a%=%C%I$K$O(B`!'$B$rIU$1$k!#(B

$BNc(B:

split
split! # split$B$NGK2uE*%P!<%8%g%s(B

$BDj?tL>(B

$B%/%i%9!&%b%8%e!<%kL>0J30$NDj?tL>$O!"$9$Y$FBgJ8;z$H$7!"C18l$N6h@Z(B $B$j$K(B`_'$B$rMQ$$$k!#(B

$BNc(B:

EXAMPLE_CONSTANT

$BJQ?tL>(B

$BJQ?tL>$O!"$9$Y$F>.J8;z$H$7!"C18l$N6h@Z$j$K(B`_'$B$rMQ$$$k!#(B

$BNc(B:

tmp
local_variable
@instance_variable
$global_variable

$B%U%!%$%kL>(B

$B%U%!%$%kL>$O!"$9$Y$F>.J8;z$H$7!"C18l$N6h@Z$j$K(B`-'$B$rMQ$$$k!#(B $B$^$?!"%U%!%$%kCf$NA0$rJQ49$7$?$b$N$r%U%!%$%kL>(B $B$K;HMQ$9$k!#(B($B%b%8%e!<%k$rL>A06u4V$H$7$F;HMQ$9$k>l9g$O!"%G%#%l%/%H(B $B%j$r;HMQ$7$F3,AX9=B$$rI=8=$9$k!#(B)

$BNc(B:

foo.rb # $B%/%i%9(BFoo$B$rDj5A(B
foo-bar.rb # $B%/%i%9(BFooBar$B$rDj5A(B
foo/bar-baz.rb # $B%/%i%9(BFoo::BarBaz$B$rDj5A(B

Copyright (C) 2007 Shugo Maeda

licensed under Creative Commons Attribution License