るりまサーチ

最速Rubyリファレンスマニュアル検索!
214件ヒット [1-100件を表示] (0.023秒)

別のキーワード

  1. argf.class lines
  2. argf.class each
  3. argf.class each_line
  4. class new
  5. argf.class gets

検索結果

<< 1 2 3 > >>

Module#<=>(other) -> Integer | nil (18172.0)

self と other の継承関係を比較します。

...のクラスやモジュール

//emlist[例][ruby]{
module Foo
end
class
Bar
include Foo
end
class
Baz < Bar
end
class
Qux
end
p Bar <=> Foo # => -1
p Baz <=> Bar # => -1
p Baz <=> Foo # => -1
p Baz <=> Qux # => nil
p Qux <=> Baz # => nil

p Baz <=> Object.new # => nil
//}...

1.6.8から1.8.0への変更点(まとめ) (588.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...
...-05) [i586-linux]
[537771634, #<Class:Object>]
[537771634, #<Class:Object>]

さらに、オブジェクトの特異クラスのスーパークラスの特異クラスと
オブジェクトの特異クラスの特異クラスのスーパークラスは同じなのだそう...
...(^^;;

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]...

Ruby用語集 (198.0)

Ruby用語集 A B C D E F G I J M N O R S Y

...

https://mruby.org/

: main
トップレベルにおける self。Object クラスのインスタンスである。

===[a:N] N

: nil
NilClass の唯一のインスタンス。また、そのオブジェクトを指す擬似変数の名前。
論理値としては偽である。

Ruby...
...宙船演算子
: spaceship operator
Comparable モジュールが利用する、二つのオブジェクトの順序関係を表す
演算子 <=> の俗称。

: 埋め込みドキュメント
: embedded document
ソースコード中の =begin 行から =end 行まで。コメントとみな...
...する。

オブジェクト空間に関する情報は ObjectSpace クラスで得ることが
できる。

: オープンクラス
: open class
組込みのクラスが再定義可能であること。
Ruby は String や Integer といった基本的なクラスも自由に改変でき...

ruby 1.8.3 feature (168.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...
...: 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_variable_...
...した。((<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...

Rubyで使われる記号の意味(正規表現の複雑な記号は除く) (108.0)

Rubyで使われる記号の意味(正規表現の複雑な記号は除く) ex q num per and or  plus minus ast slash hat sq  period comma langl rangl eq tilde  dollar at under lbrarbra  lbra2rbra2 lbra3rbra3 dq colon ac  backslash semicolon

...タの区切り。

===[a:langl] <

: 3 < 5

「より小さい」比較演算子

: 3 <= 5

「より小さいか等しい」比較演算子

: 3 <=> 5

基本的な比較演算子。ほかの比較演算子はこの演算子を元に Comparable モジュールで定義されています。
...
...でを文字列とする行指向のリテラルです。

: class Foo < Super

クラス定義でスーパークラスを指定しています。
d:spec/def#class

: class << obj

特異クラス定義。d:spec/def#singleton_classを参照。

===[a:rangl] >

: 3 > 5

「より大きい」...
...。d:spec/variables#instanceを参照。

: @@xxx

クラス変数。d:spec/variables#classを参照。

: def +@ または def -@

単項演算子 +X や -X を定義するときの表記法。
//emlist{
class
Symbol
def +@
self.upcase
end
end

puts(+:joke) #=> JOKE
//}

===[a...

絞り込み条件を変える

NEWS for Ruby 2.7.0 (78.0)

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

...ted です。 15575
この警告は「-W:no-deprecated」オプションで止められます。

//emlist{
def foo
class
<< Object.new
yield #=> warning: `yield' in class syntax will not be supported from Ruby 3.0. 15575
end
end
foo { p :ok }
//}

* 引数を転送する記法「(...)...
...nd endless ranges:
-1.clamp(0..) #=> 0
3.clamp(..2) #=> 2
//}

* Complex
* 新規メソッド
* Complex#<=>が追加されました。
その結果、「0 <=> 0i」がNoMethodErrorを発生しなくなりました。 15857

* Dir
* 変更されたメソッド
* Dir...
...sday?) #=> next Tuesday
//}
//emlist[Enumerator::Lazy#eager][ruby]{
a = %w(foo bar baz)
e = a.lazy.map {|x| x.upcase }.map {|x| x + "!" }.eager
p e.class #=> Enumerator
p e.map {|x| x + "?" } #=> ["FOO!?", "BAR!?", "BAZ!?"]
//}
//emlist[Enumerator::Lazy#with_index][ruby]{
("a"..).lazy...

演算子式 (60.0)

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

...)
* / %
+ -
<< >>
&
| ^
> >= < <=
<=>
== === != =~ !~
&&
||
.. ...
?:(条件演算子)...
...ェクトに対しての、式 2 から式 n までを
引数とする []= メソッド呼び出しに変換されます。

//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...
...//emlist[例][ruby]{
class
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, tru...

Enumerable#sort_by -> Enumerator (58.0)

ブロックの評価結果を <=> メソッドで比較することで、self を昇 順にソートします。ソートされた配列を新たに生成して返します。

...ブロックの評価結果を <=> メソッドで比較することで、self を昇
順にソートします。ソートされた配列を新たに生成して返します。

つまり、以下とほぼ同じ動作をします。

//emlist[例][ruby]{
class
Array
def sort_by
self.map {|i|...
...[yield(i), i] }.
sort {|a, b| a[0] <=> b[0] }.
map {|i| i[1]}
end
end
//}

Enumerable#sort と比較して sort_by が優れている点として、
比較条件が複雑な場合の速度が挙げられます。
sort_by を使わない以下の例では比較を行う度に downcase...
...行回数の検証結果を参照してみてください。

//emlist[][ruby]{
class
Integer
def count
$n += 1
self
end
end

ary = []
1.upto(1000) {|v| ary << rand(v) }

$n = 0
ary.sort {|a,b| a.count <=> b.count }
p $n # => 18200

$n = 0
ary.sort_by {|v| v.count }
p $n...

Enumerable#sort_by {|item| ... } -> [object] (58.0)

ブロックの評価結果を <=> メソッドで比較することで、self を昇 順にソートします。ソートされた配列を新たに生成して返します。

...ブロックの評価結果を <=> メソッドで比較することで、self を昇
順にソートします。ソートされた配列を新たに生成して返します。

つまり、以下とほぼ同じ動作をします。

//emlist[例][ruby]{
class
Array
def sort_by
self.map {|i|...
...[yield(i), i] }.
sort {|a, b| a[0] <=> b[0] }.
map {|i| i[1]}
end
end
//}

Enumerable#sort と比較して sort_by が優れている点として、
比較条件が複雑な場合の速度が挙げられます。
sort_by を使わない以下の例では比較を行う度に downcase...
...行回数の検証結果を参照してみてください。

//emlist[][ruby]{
class
Integer
def count
$n += 1
self
end
end

ary = []
1.upto(1000) {|v| ary << rand(v) }

$n = 0
ary.sort {|a,b| a.count <=> b.count }
p $n # => 18200

$n = 0
ary.sort_by {|v| v.count }
p $n...

Fiddle::Closure (48.0)

コールバック関数を表すクラスです。

...でオブジェクトを生成することで利用します。

require 'fiddle'
include Fiddle # TYPE_* を使うために include する

class
Compare < Fiddle::Closure
# qsort の比較関数は 型が int(*)(void*, void*) であるため、
# このメソッドには DL::CPtr...
...指す先は比較している文字なので、
# DL::CPtr#to_s で1文字の文字列に変換している
def call(x, y)
x.to_s(1) <=> y.to_s(1)
end
end

libc = DL.dlopen("/lib/libc.so.6")
qs = Fiddle::Function.new(libc["qsort"],
[TYPE_VOIDP,...
...p s # => "()07Uabcqx"

Class
.new を使うことで、サブクラスを明示的に作ることなしに
コールバックオブジェクトを作ることができます。
require 'fiddle'
include Fiddle # TYPE_* を使うために include する
compare = Class.new(Fiddle::Closure){...

絞り込み条件を変える

<< 1 2 3 > >>