Skip to content

Instantly share code, notes, and snippets.

View Shinpeim's full-sized avatar

Shinpei Maruyama Shinpeim

View GitHub Profile
// 連想配列,またはMap,またはDictionaryと呼ばれるもの
// JavaSctiptではこれをObjectと呼んでいる。
// Dictionaryの名の通り、「ある値」でそれを引くと
// それに対応する値を得ることができる。
var digits = {
"zero": 0,
"one": 1,
"two": 2,
"three": 3,
"four": 4,
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
class Bento
attr_reader :price
attr_writer :seals
def initialize(price)
@price = price
@seals = []
end
def discount_ammount
class Nyan
%w(a b c d).each do |meth|
define_method(meth) do |arg|
p arg
end
end
end
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 _
class Nyan(a: String) {
a = a + "!" // error: reassignment to val
def b = a
}
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)
(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
(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
(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