24件ヒット
[1-24件を表示]
(0.277秒)
検索結果
-
Module
# class _ variable _ set(name , val) -> object (18208.0) -
クラス/モジュールにクラス変数 name を定義して、その値として val をセットします。val を返します。
...をセットします。val を返します。
@param name String または Symbol を指定します。
//emlist[例][ruby]{
class Fred
@@foo = 99
def foo
@@foo
end
end
def Fred.foo(val)
class_variable_set(:@@foo, val)
end
p Fred.foo(101) # => 101
p Fred.new.foo # => 101
//}... -
ruby 1
. 8 . 3 feature (36.0) -
ruby 1.8.3 feature *((<ruby 1.8 feature>)) *((<ruby 1.8.2 feature>))
...y-talk:146894>))
$ cat test_dlg.rb
foo = Object.new
foo2 = SimpleDelegator.new(foo)
def foo.bar
puts "bar"
end
foo2.bar
$ ruby-1.8.2 -r delegate test_dlg.rb
test_dlg.rb:6: undefined method `bar' for #<Object:0x4021b0a0> (NoMethodError)
$ ruby-1.......t [ruby] [new]
: Module#class_variable_set [ruby] [new]
クラスメソッドから((<変数と定数/クラス変数>))にアクセスするための
((<Module#class_variable_get|Module/class_variable_get>)) と
((<Module#class_variable_set|Module/class_variable_set>)) が
追加され......def Fred.foo
@@foo = 101 #=> @@foo は Fred クラスのクラス変数ではない。
end
def Fred.foo_foo
class_variable_set(:@@foo, 101) # self が Fred クラス自身であることに注意。クラス変数 @@foo に値をセットする。
end...