GPSJG 3VCZ 1ZUIPO 4DBMB for x in 0..2 do puts(x) end for x in range(3): print(x) for (n <- 0 to 2) { println(n) } b = true if b then puts("true!") else puts("false!") end b = True if b: print("true!") else: print("false!") val b = true if (b) { println("true!") } else { println("false!") }
TXJUDI 3VCZ 1ZUIPO 4DBMB x = "Ruby" case x when "Ruby" then puts("this is ruby") when "Python" then puts("this is python") when "Scala" then puts("this is scala") end o = "Python" if o is "Ruby": print("this is ruby!") elif o is "Python": print("this is python!") elif o is "Scala": print("this is scala!") val o = "Scala" o match { case "Ruby" => println("this is ruby!") case "Python" => println("this is python!") case "Scala" => println("this is scala!") case _ => // No Action }
Ϋϥε 3VCZ 1ZUIPO 4DBMB class Foo def say() puts("Foo!") end end Foo.new.say() class Foo: def say(self): print("Foo!") Foo().say() class Foo { def say() = println("Foo!") } new Foo().say()
ίϨΫγϣϯૢ࡞ 3VCZ 1ZUIPO 4DBMB [1,2,3].map { |x| x + 1 } map(lambda x: x + 1, [1,2,3]) [x + 1 for x in [1, 2, 3]] List(1,2,3).map { x => x + 1 } List(1,2,3).map(_ + 1) [1,2,3].select { |x| x % 2 == 0 } filter(lambda x: x % 2 == 0, [1,2,3]) [x for x in [1,2,3] if x % 2 == 0] List(1,2,3).filter(_ % 2 == 0)
NJYJO 3VCZ module Foo def say() puts("Foo!") end end module Bar include Foo def say() puts("Bar!") end end module Baz include Foo def say() puts("Baz!") end end class Qux include Bar include Baz def say() puts("Qux!") end end Qux.new.say()