るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

キーワード

検索結果

<< 1 2 > >>

BasicObject#! -> bool (21210.0)

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

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

@
return オブジェクトが偽であれば真、さもなくば偽

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

attr_reader :count...
...ef !
@
count += 1
super
end

end


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

puts recorder.count #=> 3
//}

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

end

another_false = AnotherFalse.new

# another_falseは*真*
puts...
..."another false is a truth" if another_false
#=> "another false is a truth"
//}...

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

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

...

@
param suffix 末尾から削除する文字列を指定します。

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

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

@
see String#chomp!
@
see String#chop!
@
see String#d...
...elete_prefix!
@
see String#delete_suffix
@
see String#end_with?...

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

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

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

デフォルトでは self == other を評価した後に結果を論理否定して返します。
このため、サブクラスで BasicObject#== を再定義しても != とは自動的に整合性が
とれるように...
...ct#!= 自身や BasicObject#! を再定義した際には、ユーザーの責任で
整合性を保たなくてはなりません。

このメソッドは主に論理式の評価に伴って副作用を引き起こすことを目的に
再定義するものと想定されています。

@
param ot...
...
@
see BasicObject#==, 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 r...

OptionParser#parse!(argv = self.default_argv, into: nil) -> [String] (9237.0)

与えられた argv をパースします。

...

OptionParser#permute! と同様に argv を破壊的にパースします。
環境変数に POSIXLY_CORRECT が設定されている場合は、
OptionParser#order! と同様に振舞います。

@
param argv パースしたい引数を文字列の配列で指定します。

@
param into オ...
...プションを格納するハッシュを指定します。
指定したハッシュにはオプションの名前をキーとして、OptionParser#onに渡されたブロックの値が格納されます。
キーの名前はロングオプションが定義されていれ...
...

@
raise OptionParser::ParseError パースに失敗した場合、発生します。
実際は OptionParser::ParseError のサブク
ラスになります。

//emlist[例][ruby]{
require "optparse"

opts = OptionParser.new do |opts|...

OptionParser#parse!(argv = self.default_argv) -> [String] (9231.0)

与えられた argv をパースします。

...

OptionParser#permute! と同様に argv を破壊的にパースします。
環境変数に POSIXLY_CORRECT が設定されている場合は、
OptionParser#order! と同様に振舞います。

@
param argv パースしたい引数を文字列の配列で指定します。


@
raise OptionPar...
...実際は OptionParser::ParseError のサブク
ラスになります。

//emlist[例][ruby]{
require "optparse"

opts = OptionParser.new do |opts|
opts.on_head("-i", "--init")
opts.on("-u", "--update")
opts.on_tail("-h", "--help")
end


ARGV...
...# => ["-i", "-u", "-h", "test"]
opts.parse(ARGV) # => ["test"]
ARGV # => ["-i", "-u", "-h", "test"]
opts.parse!(ARGV) # => ["test"]
ARGV # => ["test"]
//}...

絞り込み条件を変える

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

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

...boundMethod を返します。

@
param name メソッド名を Symbol または String で指定します。

@
raise NameError self に存在しないメソッドを指定した場合に発生します。

@
see Module#public_instance_method, Object#method

//emlist[例][ruby]{
class Interpreter
de...
...int "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" => instance_method(:do_d),
"e" => instance_method(:do_e),
"v" => instance_method(:do_v)
}
def interpret(str...
...ing)
string.each_char {|b| Dispatcher[b].bind(self).call }
end

end


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

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

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

...ンプレート文字列 template にしたがってアンパックし、
それらの要素を含む配列を返します。

@
param template pack テンプレート文字列
@
return オブジェクトの配列


以下にあげるものは、Array#pack、String#unpack
のテンプレ...
...の説明の中で、
short や long はシステムによらずそれぞれ 2, 4バイトサ
イズの数値(32ビットマシンで一般的なshort, longのサイズ)を意味していま
す。s, S, l, L に対しては直後に _ または ! を "s_" あるいは "s!" のように
続けるこ...
...テム依存の short, long のサイズにすることもできます。

i, I (int)のサイズは常にシステム依存であり、n, N, v, V
のサイズは常にシステム依存ではない(!をつけられない)ことに注意してください。

つまり、IO#ioctl などで C の構...
...レート文字列 template にしたがってアンパックし、
それらの要素を含む配列を返します。

@
param template pack テンプレート文字列
@
return オブジェクトの配列


以下にあげるものは、Array#pack、String#unpack、String#unpack1
...

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

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

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

このメソッドは case 式での振る舞いを考慮して、
各クラスの性質に合わせて再定義すべきです。

デフォルトでは内部で Object#== を呼び出します。

when 節の式...
...

@
param other 比較するオブジェクトです。

//emlist[][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


p...
...uts result #=> "child"

def check arg
case arg
when /ruby(?!\s*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....

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

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

...ます。

Method#>> とは呼び出しの順序が逆になります。

@
param callable Proc、Method、もしくは任意の call メソッドを持ったオブジェクト。

//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...
.../}

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

end


File.write('testfile', <<~TEXT)
Hello, World!
Hello, Ruby!
T
EXT

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

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

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

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

...ます。

Method#<< とは呼び出しの順序が逆になります。

@
param callable Proc、Method、もしくは任意の call メソッドを持ったオブジェクト。

//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...
.../}

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

end


File.write('testfile', <<~TEXT)
Hello, World!
Hello, Ruby!
T
EXT

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

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

絞り込み条件を変える

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

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

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

テンプレートは
型指定文字列とその長さ(省略時は1)を並べたものです。長さと
して * が指定された時は「残りのデ...
...字列の通りです。

buffer が指定されていれば、バッファとして使って返値として返します。
もし template の最初にオフセット (@) が指定されていれば、
結果はオフセットの後ろから詰められます。
buffer の元の内容がオフセ...
...てください。
buffer のサイズ(capacity)が足りなければ、packはメモリを確保します。

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

@
param template 自身のバイナリとしてパックする...
<< 1 2 > >>