$ docker run -d --name memcached memcached
b40a0f915d7ade1b6ad91c7cc9b2257da1013c21ff61821cc1a59d597b9f734b
docker ps コマンドで実行状況を確認すると実行されていることが確認できます。
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a40a0f915d7a memcached "/entrypoint.sh memca" About a minute ago Up 59 seconds 11211/tcp memcached
// Keywords
<- // Used on for-comprehensions, to separate pattern from generator
=> // Used for function types, function literals and import renaming
// Reserved
( ) // Delimit expressions and parameters
[ ] // Delimit type parameters
{ } // Delimit blocks
. // Method call and path separator
// /* */ // Comments
# // Used in type notations
: // Type ascription or context bounds
<: >: <% // Upper, lower and view bounds
" """ // Strings
' // Indicate symbols and characters
@ // Annotations and variable binding on pattern matching
` // Denote constant or enable arbitrary identifiers
, // Parameter separator
; // Statement separator
_* // vararg expansion
_ // Many different meanings
どちらも記号を名前としたメソッドを定義することで演算子を定義できる。
class Foo
def +(other)
"add method"
end
end
foo1 = Foo.new
foo2 = Foo.new
foo1 + foo2 # "add method"
class Foo {
def +(other: Foo): String = "add method"
}
val foo1 = new Foo
val foo2 = new Foo
foo1 + foo2 // "add method"
引数のデフォルト値
Ruby
class Foo
def bar(baz = 1)
baz
end
end
foo = Foo.new
foo.bar() # => 1
foo.bar(2) # => 2
Scala
class Foo {
def bar(baz: Int = 1): Int = {
baz
}
}
val foo = new Foo()
foo.bar() // => 1
foo.bar(2) // => 2
可変長引数
Rubyでは定義するときも呼び出すときも * という記号をまえにつける。
class Foo
def bar(baz, *hoge)
# 2つめ以降の引数はhogeに配列として入る
end
end
foo = Foo.new
baz = 1
hoge = ["foo", "bar"]
foo.bar(baz, *hoge)
class Foo {
def bar(baz: Int, bar: String*): Unit = {
// 2つめ以降の引数は bar にSeqとして入る
}
}
val foo = new Foo
val baz = 1
val hoge = Seq("foo", "bar")
foo.bar(baz, hoge:_*)