This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 連想配列,またはMap,またはDictionaryと呼ばれるもの | |
// JavaSctiptではこれをObjectと呼んでいる。 | |
// Dictionaryの名の通り、「ある値」でそれを引くと | |
// それに対応する値を得ることができる。 | |
var digits = { | |
"zero": 0, | |
"one": 1, | |
"two": 2, | |
"three": 3, | |
"four": 4, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function returnDouble(x){ | |
var result = x * 2; //引数を2倍にして | |
return result; // それを返すという関数 | |
} | |
var n = 10; | |
var m = returnDouble(n); //returnDoubleをnを引数にして呼び出して、returnされた値を m に代入 | |
console.log(n); // 10 | |
console.log(m); // 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bento | |
attr_reader :price | |
attr_writer :seals | |
def initialize(price) | |
@price = price | |
@seals = [] | |
end | |
def discount_ammount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Nyan | |
%w(a b c d).each do |meth| | |
define_method(meth) do |arg| | |
p arg | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> case class Nyan(a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int, h: Int, i: Int, j: Int, k: Int, l: Int, m: Int, n: Int, o: Int, p: Int, q: Int, r: Int, s: Int, t: Int, u: Int, v: Int, w: Int, x: Int, y: Int, z: Int) | |
defined class Nyan | |
scala> Nyan.apply _ | |
<console>:10: error: implementation restricts functions to 22 parameters | |
Nyan.apply _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Nyan(a: String) { | |
a = a + "!" // error: reassignment to val | |
def b = a | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Tree[A]{ | |
def map[B](f: A => B):Tree[B] | |
def forEach(f: A => Unit):Unit | |
} | |
case class Node[A](value:A, left:Tree[A], right:Tree[A]) extends Tree[A] { | |
def map[B](f: A => B): Node[B] = Node(f(value), left.map(f), right.map(f)) | |
def forEach(f: A => Unit): Unit = { | |
f(value) | |
left.forEach(f) | |
right.forEach(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(global){ | |
Nyan = function(a, b){ | |
this.a = a; | |
this.b = b; | |
}; | |
Nyan.prototype.klass = 'Nyan'; //ださすぎ | |
Nyan.prototype.nyan = function(){return this.a + this.b}; | |
global.Nyan = Nyan; // export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(global){ | |
Nyan = function(a, b){ | |
this.a = a; | |
this.b = b; | |
}; | |
Nyan.prototype.klass = 'Nyan'; | |
Nyan.prototype.nyan = function(){return this.a + this.b}; | |
global.Nyan = Nyan; // export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(global){ | |
Nyan = function(a, b){ | |
this.a = a; | |
this.b = b; | |
}; | |
Nyan.prototype.klass = 'Nyan'; // ここがクソださい | |
Nyan.prototype.nyan = function(){return this.a + this.b}; | |
global.Nyan = Nyan; // export |