クラス変数 (class variable) または、静的メンバ変数 (static member variable)、静的フィールド (static field) とは、同一クラス・派生クラスで共有される変数である。そのため、関連クラスに渡って共通に使用できるグローバル変数(大域変数)であるともいえる。 これに対して、インスタンスごとに確保される変数のことを、インスタンス変数あるいは単にフィールド (計算機科学)、データメンバ、メンバ変数などと呼ぶ。 UMLではクラス変数のことを、特別な意味を持つ属性としてクラススコープ (class scope) と呼ぶ。 # Ruby Script class A @@n="Default Value" def printClassVariable p @@n end def setClassVariable(var) @@n=var end end
This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages) This article possibly contains original research. Please improve it by verifying the claims made and adding inline citations. Statements consisting only of original research should be removed. (September 2013) (Learn how and when to remove this message) T
オブジェクト指向プログラミングにおいてメタクラスとは、インスタンスがクラスとなるクラスのことである。通常のクラスがそのインスタンスの振る舞いを定義するように、メタクラスはそのインスタンスであるクラスを、そして更にそのクラスのインスタンスの振る舞いを定義する。全てのオブジェクト指向プログラミング言語でメタクラスが利用できるわけではない。利用できるものの中でもクラスの振る舞いが定義できる範囲は様々である。各言語はそれぞれ独自のメタオブジェクトプロトコル(MOP)を備えている[1]。メタオブジェクトプロトコルとは、クラスそのものの挙動をもオブジェクト指向のルールで記述し、初期化やインスタンス化のルール、実行状態の管理などをカスタマイズする機構である。Smalltalk、Common Lispが代表的である。 class Car(object): __slots__ = ['make', 'mod
super ブロック付きメソッド呼び出し yield ブロックパラメータの挙動 例: foo.bar() foo.bar bar() print "hello world\n" print Class.new Class::new 文法: [式 `.'] 識別子 [`(' 式 ... [`*' [式]],[`&' 式] `)'] [式 `::'] 識別子 [`(' 式 ... [`*' [式]],[`&' 式] `)'] メソッド呼び出し式はレシーバ(`.' の左側の式の値)のメソッドを呼び 出します。レシーバが指定されない時は self のメソッドを呼び出しま す。 `.' と `::' とはほぼ同じ意味です。但し、定数を表す場合は、 `::' を使わなければいけません(例: Math::PI)。逆に、 Klass::Foo とした場合、常に定数と見なされるという制限があります。 `::
In computer science, a mutator method is a method used to control changes to a variable. They are also widely known as setter methods. Often a setter is accompanied by a getter, which returns the value of the private member variable. They are also known collectively as accessors. The mutator method is most often used in object-oriented programming, in keeping with the principle of encapsulation. A
When you first get started with the Ruby programming and you come from a different language, the only tricky piece is often Ruby’s approach to block/closure/anonymous functions. Sure the metaprogramming seems a bit odd, but you don’t have to use it. That’s why a lot of developers think that Ruby is a simple language. Turns out that when you dig a bit further, you realize that Ruby is actually quit
In Java you just have classes (both abstract and concrete) and interfaces. The Ruby language provides classes, modules, and a mix of both. In this post I want to dive into mixins in Ruby. In the Ruby language a mixin is a class that is mixed with a module. In other words the implementation of the class and module are joined, intertwined, combined, etc. A mixin is a different mechanism to the exten
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く