Java VS Ruby
Javaで書くif
int foo = 0, bar;
if(foo == 0){
bar = 10;
}
Rubyで書くif
foo = 0
if foo == 0
bar = 10
end
Javaで書くfor
for(int i = 0, i < 10, i++){
System.out.println(i);
}
Rubyで書くfor
for i in 0…10
print i
end
Javaで書くクラスとメソッド
public class foo extends bar {
public void main(String[] args) {
do_something();
}
public int do_something() {
return 0;
}
}
Rubyで書くクラスとメソッド
class foo < bar
def main
do_something
end
def do_something
return 0
end
end
Javaで書くアクセサ
private foo;
private bar;
private baz;
public String getFoo()
{
return foo;
}
public void setFoo(String foo)
{
this.foo = foo;
}
public String getBar()
{
return bar;
}
public void setBaz(String baz)
{
this.baz = baz;
}
Rubyで書くアクセサ
attr_accessor:foo
attr_reader:bar
attr_writer:baz
コメントを残す