22件ヒット
[1-22件を表示]
(0.045秒)
別のキーワード
検索結果
-
Module
# class _ variable _ set(name , val) -> object (45220.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 (138.0) -
ruby 1.8.3 feature *((<ruby 1.8 feature>)) *((<ruby 1.8.2 feature>))
...は、$SAFE レベル が 0 のとき
禁止されるようになりました。
$ cat mthd_taint.rb
th = Thread.new{
$SAFE = 3
class Hoge
def foo
puts "safe level: #{$SAFE}"
end
end
}
th.join
p $SAFE
Hoge.new.foo
$ ruby......6-07
: Module#class_variable_get [ruby] [new]
: Module#class_variable_set [ruby] [new]
クラスメソッドから((<変数と定数/クラス変数>))にアクセスするための
((<Module#class_variable_get|Module/class_variable_get>)) と
((<Module#class_variable_set|Module/class_varia......。((<ruby-talk:144741>))
class Fred
@@foo = 99
def foo
@@foo
end
end
def Fred.foo
@@foo = 101 #=> @@foo は Fred クラスのクラス変数ではない。
end
def Fred.foo_foo
class_variable_set(:@@foo, 101) # self が F...