るりまサーチ

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

別のキーワード

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

ライブラリ

クラス

キーワード

検索結果

BasicObject#! -> bool (21192.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"
//}...

BasicObject#!=(other) -> bool (9243.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...

Module#instance_method(name) -> UnboundMethod (6143.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!
//}...

Object#===(other) -> bool (3203.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...
...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 (3079.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 (3079.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#>>...