るりまサーチ

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

別のキーワード

  1. rbconfig ruby
  2. fiddle ruby_free
  3. fiddle build_ruby_platform
  4. rake ruby
  5. rubygems/defaults ruby_engine

クラス

キーワード

検索結果

<< 1 2 > >>

BasicObject#! -> bool (18176.0)

オブジェクトを真偽値として評価し、その論理否定を返します。

...しても Ruby の制御式において nil や false 以外が偽として
扱われることはありません。

@return オブジェクトが偽であれば真、そうでない場合は偽

//emlist[例][ruby]{
class NegationRecorder < BasicObject
def initialize
@count = 0
end

attr_r...
...eader :count

def !
@count += 1
super
end

end


recorder = NegationRecorder.new
!
recorder
!
!!!!!!recorder
puts 'hoge' if !recorder

puts recorder.count #=> 3
//}

//emlist[例][ruby]{
class AnotherFalse < BasicObject
def !
true
end

end

another_false = AnotherFalse.new

# another_...

BasicObject#!=(other) -> bool (6127.0)

オブジェクトが other と等しくないことを判定します。

...返します。
このため、サブクラスで BasicObject#== を再定義しても != とは自動的に整合性が
とれるようになっています。

ただし、 BasicObject#!= 自身や BasicObject#! を再定義した際には、ユーザーの責任で
整合性を保たなくては...
...icObject#==, BasicObject#!

//emlist[例][ruby]{
class NonequalityRecorder < BasicObject
def initialize
@count = 0
end

attr_reader :count

def !=(other)
@count += 1
super
end

end

recorder = NonequalityRecorder.new

recorder != 1
puts 'hoge' if recorder != "str"

p recorder.coun...

String#delete_suffix!(suffix) -> self | nil (6115.0)

self の末尾から破壊的に suffix を削除します。

...ます。

@return 削除した場合は self、変化しなかった場合は nil

//emlist[][ruby]{
"hello".delete_suffix!("llo") # => "he"
"hello".delete_suffix!("hel") # => nil
//}

@see String#chomp!
@see String#chop!
@see String#delete_prefix!
@see String#delete_suffix
@see String#end_with?...

Array#pack(template) -> String (705.0)

配列の内容を template で指定された文字列にしたがって、 バイナリとしてパックした文字列を返します。

...サイズ(capacity)が足りなければ、packはメモリを確保します。

//emlist[例][ruby]{
['!'].pack('@1a', buffer: 'abc') # => "a!"
['!'].pack('@5a', buffer: 'abc') # => "abc\u0000\u0000!"
//}

@param template 自身のバイナリとしてパックするためのテンプレート...
...に _ または ! を "s_" あるいは "s!" のように
続けることでシステム依存の short, long のサイズにすることもできます。

i, I (int)のサイズは常にシステム依存であり、n, N, v, V
のサイズは常にシステム依存ではない(!をつけられな...
...造体を渡すときのように、
システム依存のサイズとエンディアンに合わせる必要があるときには
s!, S!, i!, I!, l!, L!, q!, Q!, j!, J! を用います。
また、ネットワークプロトコルやファイルフォーマットのように、
システムに依...

Array#pack(template, buffer: String.new) -> String (705.0)

配列の内容を template で指定された文字列にしたがって、 バイナリとしてパックした文字列を返します。

...サイズ(capacity)が足りなければ、packはメモリを確保します。

//emlist[例][ruby]{
['!'].pack('@1a', buffer: 'abc') # => "a!"
['!'].pack('@5a', buffer: 'abc') # => "abc\u0000\u0000!"
//}

@param template 自身のバイナリとしてパックするためのテンプレート...
...に _ または ! を "s_" あるいは "s!" のように
続けることでシステム依存の short, long のサイズにすることもできます。

i, I (int)のサイズは常にシステム依存であり、n, N, v, V
のサイズは常にシステム依存ではない(!をつけられな...
...造体を渡すときのように、
システム依存のサイズとエンディアンに合わせる必要があるときには
s!, S!, i!, I!, l!, L!, q!, Q!, j!, J! を用います。
また、ネットワークプロトコルやファイルフォーマットのように、
システムに依...

絞り込み条件を変える

Array#pack(template) -> String (699.0)

配列の内容を template で指定された文字列にしたがって、 バイナリとしてパックした文字列を返します。

...に _ または ! を "s_" あるいは "s!" のように
続けることでシステム依存の short, long のサイズにすることもできます。

i, I (int)のサイズは常にシステム依存であり、n, N, v, V
のサイズは常にシステム依存ではない(!をつけられな...
...造体を渡すときのように、
システム依存のサイズとエンディアンに合わせる必要があるときには
s!, S!, i!, I!, l!, L!, q!, Q!, j!, J! を用います。
また、ネットワークプロトコルやファイルフォーマットのように、
システムに依...
...! と組み合わせることも可能です。

まとめると以下のようになります。

: エンディアン非依存、整数サイズ非依存 (ネットワークプロトコルなどに適切)
//emlist{
n: big endian unsigned 16bit
N: big endian unsigned 32bit
v: little endian...

String#unpack(template) -> Array (699.0)

Array#pack で生成された文字列を テンプレート文字列 template にしたがってアンパックし、 それらの要素を含む配列を返します。

...に _ または ! を "s_" あるいは "s!" のように
続けることでシステム依存の short, long のサイズにすることもできます。

i, I (int)のサイズは常にシステム依存であり、n, N, v, V
のサイズは常にシステム依存ではない(!をつけられな...
...造体を渡すときのように、
システム依存のサイズとエンディアンに合わせる必要があるときには
s!, S!, i!, I!, l!, L!, q!, Q!, j!, J! を用います。
また、ネットワークプロトコルやファイルフォーマットのように、
システムに依...
...! と組み合わせることも可能です。

まとめると以下のようになります。

: エンディアン非依存、整数サイズ非依存 (ネットワークプロトコルなどに適切)
//emlist{
n: big endian unsigned 16bit
N: big endian unsigned 32bit
v: little endian...

Method#<<(callable) -> Proc (63.0)

self と引数を合成した Proc を返します。

...ト。

//emlist[例][ruby]{
def f(x)
x * x
end


def g(x)
x + x
end


# (3 + 3) * (3 + 3)
p (method(:f) << method(:g)).call(3) # => 36
//}

//emlist[call を定義したオブジェクトを渡す例][ruby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end

end


File.write('testfil...
...e', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT

pipeline = method(:pp) << WordScanner << File.method(:read)
pipeline.call('testfile') # => ["Hello", "World", "Hello", "Ruby"]
//}

@see Proc#<<, Proc#>>...

Method#>>(callable) -> Proc (63.0)

self と引数を合成した Proc を返します。

...ト。

//emlist[例][ruby]{
def f(x)
x * x
end


def g(x)
x + x
end


# (3 * 3) + (3 * 3)
p (method(:f) >> method(:g)).call(3) # => 18
//}

//emlist[call を定義したオブジェクトを渡す例][ruby]{
class WordScanner
def self.call(str)
str.scan(/\w+/)
end

end


File.write('testfil...
...e', <<~TEXT)
Hello, World!
Hello, Ruby!
TEXT

pipeline = File.method(:read) >> WordScanner >> method(:pp)
pipeline.call('testfile') # => ["Hello", "World", "Hello", "Ruby"]
//}

@see Proc#<<, Proc#>>...

Object#===(other) -> bool (63.0)

case 式で使用されるメソッドです。d:spec/control#case も参照してください。

...][ruby]{
age = 12
# (0..2).===(12), (3..6).===(12), ... が実行される
result =
case age
when 0 .. 2
"baby"
when 3 .. 6
"little child"
when 7 .. 12
"child"
when 13 .. 18
"youth"
else
"adult"
end


puts result #=> "child"

def check arg
case arg
when /ruby(?!\...
...on\s*rails)/i
"hit! #{arg}"
when String
"Instance of String class. But don't hit."
else
"unknown"
end

end


puts check([]) #=> unknown
puts check("mash-up in Ruby on Rails") #=> instance of String class. But not hit...
puts check("<Ruby's world>") #=> hit! <Ruby's world>
//}

@see O...

絞り込み条件を変える

Module#instance_method(name) -> UnboundMethod (51.0)

self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。

...

@see Module#public_instance_method, Object#method

//emlist[例][ruby]{
class Interpreter
def do_a() print "there, "; end
def do_d() print "Hello "; end
def do_e() print "!\n"; end
def do_v() print "Dave"; end
Dispatcher = {
"a" => instance_method(:do_a),
"d" => instan...
...ce_method(:do_d),
"e" => instance_method(:do_e),
"v" => instance_method(:do_v)
}
def interpret(string)
string.each_char {|b| Dispatcher[b].bind(self).call }
end

end


interpreter = Interpreter.new
interpreter.interpret('dave')
# => Hello there, Dave!
//}...
<< 1 2 > >>