るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

検索結果

<< 1 2 3 ... > >>

Object#initialize(*args, &block) -> object (18173.0)

ユーザ定義クラスのオブジェクト初期化メソッド。

...トの動作ではなにもしません。

initialize
には
Class#new に与えられた引数がそのまま渡されます。

サブクラスではこのメソッドを必要に応じて再定義されること
が期待されています。

initialize
という名前のメソッドは自動...
...][ruby]{
class Foo
def initialize name
puts "initialize Foo"
@name = name
end

end


class Bar < Foo
def initialize name, pass
puts "initialize Bar"
super name
@pass = pass
end

end


it = Bar.new('myname','0500')
p it
#=> initialize Bar
# initialize Foo
# #<Bar:0x2b68f08...

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

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

...ソッドは変化しません。

デフォルトでは、Object#clone の内部で Object#initialize_clone から、
また Object#dup の内部で Object#initialize_dup から呼ばれます。

initialize
_copy は、Ruby インタプリタが知り得ない情報をコピーするた
めに使...
... initialize_copy でコピーするよう定義しておくことで、dup や clone
を再定義する必要がなくなります。

デフォルトの Object#initialize_copy は、 freeze チェックおよび型のチェックを行い self
を返すだけのメソッドです。

initialize
_cop...
...: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.taint

check Object.new.send(:initialize_copy, obj)
#=>...
...<<obj
attr_accessor :foo
def bar
: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: #<...

1.6.8から1.8.0への変更点(まとめ) (888.0)

1.6.8から1.8.0への変更点(まとめ) * ((<1.6.8から1.8.0への変更点(まとめ)/インタプリタの変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたクラス/モジュール>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたメソッド>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加された定数>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張されたクラス/メソッド(互換性のある変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/変更されたクラス/メソッド(互換性のない変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/文法の変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/正規表現>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Marshal>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Windows 対応>)) * ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>)) * ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>)) * ((<1.6.8から1.8.0への変更点(まとめ)/バグ修正>)) * ((<1.6.8から1.8.0への変更点(まとめ)/サポートプラットフォームの追加>))

...よくわかりません(^^;

class << Object
p [self.id, self]
class << self
p [self.id, self]
end

end

=> ruby 1.6.7 (2002-03-01) [i586-linux]
[537771634, Class]
[537742484, Class]
=> ruby 1.7.3 (2002-09...
...class << Object.new
class << self.superclass
p [self.id, self]
end

class << self
p [self.superclass.id, self.superclass]
end

end

=> ruby 1.6.7 (2002-03-01) [i586-linux]
[537771634, Class]
[5...
...(({ary[n,0] = [other,...]})) と同じ(ただし self を返す)

=== Class

: ((<Class#allocate|Class/allocate>)) [new]

allocate と initialize の二つのメソッドでオブジェクトを
生成するようになりました。((<ruby-dev:14847>))
rb_define_alloc_func() も...

クラス/メソッドの定義 (582.0)

クラス/メソッドの定義 * クラス/メソッドの定義: * class * singleton_class * module * method * operator * nest_method * eval_method * singleton_method * class_method * limit * 定義に関する操作: * alias * undef * defined

...fined

===[a:class] クラス定義

//emlist[例][ruby]{
class Foo < Super
def test
# ...
end

# ...
end

//}

文法:

class 識別子 [`<' superclass ]
式..
end


文法:

class 識別子 [`<' superclass ]
式..
[rescue [erro...
...r_type,..] [=> evar] [then]
式..]..
[else
式..]
[ensure
式..]
end


クラスを定義します。クラス名はアルファベットの大文字で始まる識別子です。

rescue/ensure 節を指定し、例外処理ができ...
...セッタを定義
def initialize(x, y) # コンストラクタ
@x = x; @y = y # @がつくのがインスタンス変数(メンバ変数)
end

def ==(other_vec) # いわゆる演算子オーバーライド
other_vec.x == @x && other_vec.y == @y
end

def +(other_vec)
Ve...

ruby 1.6 feature (330.0)

ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。

...Errno::EAGAIN
Errno::EWOULDBLOCK

=> ruby 1.6.8 (2002-12-24) [i586-linux]
Errno::EAGAIN
-:2: uninitialized constant EWOULDBLOCK at Errno (NameError)

=> ruby 1.6.8 (2003-02-13) [i586-linux]
Errno::EAGAIN
Errno::EAGAIN

=...
...ーになっていました。
((<ruby-dev:17155>))

open("|-","r+") {|f|
if f
f.dup.close_write
else
sleep 1
end

}

=> ruby 1.6.7 (2002-03-01) [i586-linux]
-:3:in `close_write': closing non-duplex IO for writing (IOError)
from -:3...
...トで 2 回シグナルを送らないと終了しない不具合が修正さ
れました。((<ruby-bugs-ja:PR#223>))

trap(:TERM, "EXIT")

END
{
puts "exit"
}

Thread.start { Thread.stop }
sleep

: 2002-04-17: Regexp#inspect

((<ruby-bugs-ja:PR#222>))

p %r{\/}...

絞り込み条件を変える

パターンマッチ (282.0)

パターンマッチ * patterns * variable_binding * variable_pinning * matching_non_primitive_objects * guard_clauses * current_feature_status * pattern_syntax * some_undefined_behavior_examples

...case 文の中で利用できます。

case <expression>
in <pattern1>
...
in <pattern2>
...
in <pattern3>
...
else
...
end


in 節と when 節は1つの case 式の中に混ぜて書くことはできません。


case/in 式は 「網羅的」 です。もし case...
...ts "Connect with user '#{user}'"
in connection: {username: }
puts "Connect with user '#{username}'"
else
puts "Unrecognized structure of config"
end

# "Connect with user 'admin'" と出力
//}

一方、『in』 文は、期待されるデータ構造があらかじめ分かっている場合に...
...//emlist[][ruby]{
class Point
def initialize(x, y)
@x, @y = x, y
end


def deconstruct
puts "deconstruct called"
[@x, @y]
end


def deconstruct_keys(keys)
puts "deconstruct_keys called with #{keys.inspect}"
{x: @x, y: @y}
end

end


case Point.new(1, -2)
in px, Integer...
...を用いて実装されています。

case <expression>
in <pattern1>
...
in <pattern2>
...
in <pattern3>
...
else
...
end


in 節と when 節は1つの case 式の中に混ぜて書くことはできません。

『=>』 演算子と in 演算子で、単体の式で...
...ts "Connect with user '#{user}'"
in connection: {username: }
puts "Connect with user '#{username}'"
else
puts "Unrecognized structure of config"
end

# "Connect with user 'admin'" と出力
//}

一方、『=>』 演算子は、期待されるデータ構造があらかじめ分かっている場...

Marshal フォーマット (156.0)

Marshal フォーマット フォーマットバージョン 4.8 を元に記述しています。

...n4 = 255
when -1; n2 = n3 = n4 = 255
end


n = (0xffffff00 | n1) &
(0xffff00ff | n2 * 0x100) &
(0xff00ffff | n3 * 0x10000) &
(0x00ffffff | n4 * 0x1000000)
# p "%x" % n
n = -((n ^ 0xffff_ffff) + 1) if len < 0
n
end


p Marshal.dump(-125).unpack("x2 acC*")...
...クラス名(Symbol)の dump | 親クラスのインスタンスの dump |
//}

//emlist[例 1][ruby]{
class Foo < Array # (or String, Regexp, Hash)
end

p Marshal.dump(Foo.new([nil])).unpack("x2 a a c a3 aca*")
# => ["C", ":", 8, "Foo", "[", 6, "0"]
# ^^^ (or '"', '/', '{')
/...
...ださい。

//emlist[例 2: インスタンス変数あり][ruby]{
class Foo < Array # (or String, Regexp, Hash)
def initialize(obj)
@foo = false
super(obj)
end

end

p Marshal.dump(Foo.new([true])).unpack("x2 a a a c a3 aca caca4 a")
# => ["I", "C", ":", 8, "Foo", "[", 6, "T", 6, ":", 9...

ruby 1.8.4 feature (132.0)

ruby 1.8.4 feature ruby 1.8.4 での ruby 1.8.3 からの変更点です。

...* ((<ruby 1.8.4 feature/"Ruby/Tk">))
* ((<ruby 1.8.4 feature/REXML [compat]>))
* ((<ruby 1.8.4 feature/TCPSocket#initialize [bug]>))
* ((<ruby 1.8.4 feature/TCPServer#initialize [bug]>))
* ((<ruby 1.8.4 feature/"optparse">))
* ((<ruby 1.8.4 feature/"find">))
* ((<ruby 1.8.4 feature/Iconv...
...適合する文字列を厳密にした。((<ruby-core:03573>)),((<ruby-dev:27478>))

1) alias :"foo" :"bar"

def bar; p "bar"; end
alias :"foo" :"bar"
foo

# => ruby 1.8.4 (2005-12-22) [i686-linux]
-:2: syntax error, unexpecte...
..."$- "
2631438

# => ruby 1.8.4 (2005-12-22) [i686-linux]
-:2: syntax error, unexpected '(', expecting $end

#Tue Nov 1 14:20:11 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
#
# * eval.c (rb_call_super): should call method_missing if super is
#...

演算子式 (114.0)

演算子式 * assign * selfassign * multiassign * range * range_cond * and * or * not * cond

...= メソッド呼び出しに変換されます。

//emlist[例][ruby]{
class C
def initialize
@ary = [0,1,2,3,4,5,6,7]
end

def [](i)
@ary[i * 2]
end

def []=( i, v )
@ary[i * 2] = v
end

end

c = C.new
p c[3] # c.[]( 3 ) に変換され、その結果は 6
p c[3] = 1 #...
...C
def foo
@foo
end

def foo=( v )
@foo = v
end

end

c = C.new
c.foo = 5 # c.foo=( 5 ) のように変換される
p c.foo # => 5
//}

属性は Module#attr を使って同じように定義できます。

//emlist[例][ruby]{
class C
attr :foo, true
end

c = C.new
c.foo = 5...
...代入式も多重代入にすることができます。

//emlist[][ruby]{
class C
def foo=( v )
@foo = v
end

def []=(i,v)
@bar = ["a", "b", "c"]
@bar[i] = v
end

end


obj = C.new
obj.foo, obj[2] = 1, 2 # @foo = 1; @bar = ["a", "b", 2]
//}

左辺が `,' で終る場合や...
<< 1 2 3 ... > >>