scala:
val list = Array(1,2,3,4)
list.filter( _ % 2 == 0)
list.filter{e: Int => (e % 2 == 0)}
ruby:
list = [1,2,3,4]
list.select{|x| x % 2 == 0}
scala:
import scala.collection.mutable.HashMap
var hash =new HashMap[Int, String]
hash += (1 -> "hello")
hash += (3) #error: type mismatch;
ruby:
hash = Hash.new
hash = 3 #3
scala:
import scala.language.dynamics
class Animal extends Dynamic {
def selectDynamic(name: String) {
println("Animal wants to " + name)
}
def applyDynamic(name: String)(args: Any*) {
println("Animal wants to " + name + args.mkString(","))
}
}
scala> var a = new Animal
scala> a.say
Animal wants to say
scala> a.say("hello")
Animal wants to say hello
ruby:
class Animal
def method_missing name,*args
if args.empty?
puts "Animal says " + name.to_s
else
puts "Animal wants to " + name.to_s + args.join(",")
end
self
end
end
2.2.1 :020 > animal = Animal.new
2.2.1 :020 > animal.qualk
Animal says qualk
2.2.1 :021 > animal.say("hello")
Animal wants to say hello
scala:
trait MyClass {
def my_method = println("my method")
}
class IncludeTrait extends MyClass
scala> (new IncludeTrait).my_method
my method
ruby:
module MyModule
def my_method
puts "my_method"
end
end
class IncludeModule
include MyModule
end
2.2.1 :032 >IncludeModule.new.my_method
my_method
scala:
class Duck{
def quack = { println("duck quack..")}
def walk = { println("duck walk..")}
}
class Platypus{
def quack = { println("platypus quack..")}
def walk = { println("platypus walk..")}
}
def ActAsADuck(a: {def quack; def walk}) = {
a.quack
a.walk
}
val duck = new Duck
val paltypus = new Platypus
ActAsADuck(duck)
ActAsADuck(platypus)
ruby:
class Duck
def quack; end
def walk; end
end
class Platypus
def quack; end
def walk; end
end
def act_as_a_duck(animal)
animal.quack
animal.walk
end
duck = Duck.new
platypus = Platypus.new
act_as_a_duck(duck)
act_as_a_duck(platypus)
scala:
@Test def myTest(){
val array = List(1,2,3)
assert(array(0) === 1)
}
ruby:
test "my test" do
array = [1,2,3]
assert_equal 1, array.first
end
scala:
describe("Get of List"){
it("(0) returns the first element") {
val array = List(1,2,3)
array(0) should be 1
}
}
ruby :
describe "Get of Array" do
it "first returns the first element" do
array = [1,2,3]
array.first.should == 1
end
end
scala:
Play 是一个开源高性能 Web 框架,能够基于 Java 或 Scala 编写可扩展可伸缩的应用系统,它能自动刷新源码的变动从而具有快速开发产品的能力,它还是一个无态非堵塞的框架,易于横向扩展。Play! 框架有如下特点:高开发效率:Java EE 和 Spring 框架并不适合快速原型开发,Play 框架参考动态语言的快速开发能力,它支持热重载所有的 Java 代码和模板等,让你更快地迭代。基于 Netty 构建非堵塞异步机制。RESTJSON 支持:非常容易编写 RESTful 应用,非常适合支持 HTTP 路由。
Akka 是一个用 Scala 编写的库,用于简化编写容错的、高可伸缩性的 Java 和 Scala 的 Actor 模型应用。它已经成功运用在电信行业。系统几乎不会宕机(高可用性 99.9999999% 一年只有 31ms 宕机
ruby: Ruby on Rails 是一个用于开发数据库驱动的网络应用程序的完整框架。Rails 基于 MVC 设计模式。从视图中的 Ajax 应用,到控制器中的访问请求和反馈,到封装数据库的模型,Rails 为你提供一个纯 Ruby 的开发环境。发布网站时,你只需要一个数据库和一个网络服务器即可。