るりまサーチ

最速Rubyリファレンスマニュアル検索!
89件ヒット [1-89件を表示] (0.134秒)
トップページ > クエリ:i[x] > クエリ:end[x] > クエリ:attr_accessor[x]

別のキーワード

  1. _builtin end
  2. ripper end_seen?
  3. _builtin exclude_end?
  4. _builtin end_with?
  5. zlib stream_end?

ライブラリ

クラス

キーワード

検索結果

Module#attr_accessor(*name) -> nil (18213.0)

インスタンス変数 name に対する読み取りメソッドと書き込みメソッドの両方を 定義します。

...と書き込みメソッドの両方を
定義します。


このメソッドで定義されるメソッドの定義は以下の通りです。

//emlist[例][ruby]{
def name
@name
end

def name=(val)
@name = val
end

//}

@param name String または Symbol を 1 つ以上指定します。...

Thread::Backtrace::Location#inspect -> String (6224.0)

Thread::Backtrace::Location#to_s の結果を人間が読みやすいような文 字列に変換したオブジェクトを返します。

...race::Location#to_s の結果を人間が読みやすいような文
字列に変換したオブジェクトを返します。

//emlist[例][ruby]{
# foo.rb
class Foo
attr_accessor
:locations
def initialize(skip)
@locations = caller_locations(skip)
end

end


Foo.new(0..2).locations.map do...
...|call|
puts call.inspect
end


# => "path/to/foo.rb:5:in `initialize'"
# "path/to/foo.rb:9:in `new'"
# "path/to/foo.rb:9:in `<main>'"
//}...

Object#initialize_copy(obj) -> object (6130.0)

(拡張ライブラリによる) ユーザ定義クラスのオブジェクトコピーの初期化メソッド。

...

i
nitialize_copy は、Ruby インタプリタが知り得ない情報をコピーするた
めに使用(定義)されます。例えば C 言語でクラスを実装する場合、情報
をインスタンス変数に保持させない場合がありますが、そういった内部情
報を init...
...mlist[][ruby]{
obj = Object.new
class <<obj
attr_accessor
:foo
def bar
:bar
end

end


def check(obj)
puts "instance variables: #{obj.inspect}"
puts "tainted?: #{obj.tainted?}"
print "singleton methods: "
begin
p obj.bar
rescue NameError
p $!
end

end


obj.foo = 1
obj.tain...
...Object.new.send(:initialize_copy, obj)
#=> instance variables: #<Object:0x4019c9d4>
# tainted?: false
# singleton methods: #<NoMethodError: ...>
check obj.dup
#=> instance variables: #<Object:0x4019c9c0 @foo=1>
# tainted?: true
# singleton meth...
....initialize_copy(obj)
//}

obj2 に対してさらに obj のインスタンス変数、ファイナライザを
コピーすることで複製を作ります。 obj.clone は、さらに
特異メソッドのコピーも行います。

//emlist[][ruby]{
obj = Object.new
class <<obj
attr_accessor
...
...:bar
end

end


def check(obj)
puts "instance variables: #{obj.inspect}"
print "singleton methods: "
begin
p obj.bar
rescue NameError
p $!
end

end


obj.foo = 1

check Object.new.send(:initialize_copy, obj)
#=> instance variables: #<Object:0x4019c9d4>
# singleto...

Thread::Backtrace::Location (6048.0)

Ruby のフレームを表すクラスです。

...tions から生成されます。

//emlist[例1][ruby]{
# caller_locations.rb
def a(skip)
caller_locations(skip)
end

def b(skip)
a(skip)
end

def c(skip)
b(skip)
end


c(0..2).map do |call|
puts call.to_s
end

//}

例1の実行結果:

caller_locations.rb:2:in `a'
caller_locations.rb:5:in...
...ions.rb:8:in `c'

//emlist[例2][ruby]{
# foo.rb
class Foo
attr_accessor
:locations
def initialize(skip)
@locations = caller_locations(skip)
end

end


Foo.new(0..2).locations.map do |call|
puts call.to_s
end

//}

例2の実行結果:

i
nit.rb:4:in `initialize'
i
nit.rb:8:in `new'
i
ni...
...t.rb:8:in `<main>'

=== 参考

* Ruby VM アドベントカレンダー #4 vm_backtrace.c: https://www.atdot.net/~ko1/diary/201212.html#d4...

Thread::Backtrace::Location#absolute_path -> String (3124.0)

self が表すフレームの絶対パスを返します。

...mlist[例][ruby]{
# foo.rb
class Foo
attr_accessor
:locations
def initialize(skip)
@locations = caller_locations(skip)
end

end


Foo.new(0..2).locations.map do |call|
puts call.absolute_path
end


# => /path/to/foo.rb
# /path/to/foo.rb
# /path/to/foo.rb
//}

@see Thread::Backtrace::Locatio...

絞り込み条件を変える

Thread::Backtrace::Location#base_label -> String (3124.0)

self が表すフレームの基本ラベルを返します。通常、 Thread::Backtrace::Location#label から修飾を取り除いたもので構成 されます。

...ocation#label から修飾を取り除いたもので構成
されます。

//emlist[例][ruby]{
# foo.rb
class Foo
attr_accessor
:locations
def initialize(skip)
@locations = caller_locations(skip)
end

end


Foo.new(0..2).locations.map do |call|
puts call.base_label
end


# => initialize...
...# new
# <main>
//}

@see Thread::Backtrace::Location#label...

Thread::Backtrace::Location#to_s -> String (3124.0)

self が表すフレームを Kernel.#caller と同じ表現にした文字列を返し ます。

...//emlist[例][ruby]{
# foo.rb
class Foo
attr_accessor
:locations
def initialize(skip)
@locations = caller_locations(skip)
end

end


Foo.new(0..2).locations.map do |call|
puts call.to_s
end


# => path/to/foo.rb:5:in `initialize'
# path/to/foo.rb:9:in `new'
# path/to/foo.rb:9:in `<main>'
/...

JSON::Parser.new(source, options => {}) -> JSON::Parser (130.0)

パーサを初期化します。

...: :max_nesting
データ構造のネストの深さの最大値を指定します。デフォルトは 19 です。
チェックを無効にするにはゼロまたは偽を指定してください。
: :allow_nan
真を指定すると 4627 を無視して NaN, Infinity, -Infinity をパー...
...シュです。

//emlist[例][ruby]{
require 'json'

parser = JSON::Parser.new(DATA.read)
print parser.source

# => {
# => "Tanaka": {
# => "name":"tanaka",
# => "age":20
# => },
# => "Suzuki": {
# => "name":"suzuki",
# => "age":25
# => }
# => }

__END__
{
"Tanaka": {...
...naka",
"age":20
},
"Suzuki": {
"name":"suzuki",
"age":25
}
}
//}

//emlist[例 object_class を指定する][ruby]{
require 'json'

class Person
attr_accessor
:name, :age

def []=(key, value)
i
nstance_variable_set("@#{key}", value)
end

end


parser = JSON::Parser.new(DATA....

NEWS for Ruby 3.0.0 (60.0)

NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。

...positional arguments.
Code that resulted in deprecation warnings in Ruby 2.7 will now
result in ArgumentError or different behavior. 14183
* Procs accepting a single rest argument and keywords are no longer
subject to autosplatting. This now matches the behavior of Procs
accepting...
...tion warning
# 3.0 => a=>1}, {}]
//}

* Arguments forwarding (`...`) now supports leading arguments.
16378

//emlist{
def method_missing(meth, ...)
send(:"do_#{meth}", ...)
end

//}

* Pattern matching (`case/in`) is no longer experimental. 17260
* One-line pattern matching is redesig...
...lasses included or prepended the receiver. 9573
* Module#public, Module#protected, Module#private, Module#public_class_method, Module#private_class_method, toplevel "private" and "public" methods now accept single array argument with a list of method names. 17314
* Module#attr_accessor, Modu...