るりまサーチ

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

別のキーワード

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

クラス

キーワード

検索結果

BasicObject#! -> bool (18140.0)

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

...][ruby]{
class
NegationRecorder < BasicObject
def initialize
@count = 0
end
attr_reader :count

def !
@count += 1
super
end
end

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

puts recorder.count #=> 3
//}

//emlist[例][ruby]{
class
Anothe...
...rFalse < BasicObject
def !
true
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 (6109.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...

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

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

...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...
puts check("<Ruby's world>") #=> hit! <Ruby's wo...

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

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

...(3) # => 36
//}

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

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

pipeline = method(:pp) << WordScanner << File.method(:read)
pipeline.call('t...

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

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

...(3) # => 18
//}

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

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

pipeline = File.method(:read) >> WordScanner >> method(:pp)
pipeline.call('t...

絞り込み条件を変える

Proc#<<(callable) -> Proc (21.0)

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

...(3) # => 36
//}

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

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

pipeline = proc { |data| puts "word count: #{data.size}" } << WordScanner <<...

Proc#>>(callable) -> Proc (21.0)

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

...(3) # => 18
//}

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

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

pipeline = proc { |fname| File.read(fname) } >> WordScanner >> method(:p)
pi...

Hash#clone -> Hash (15.0)

selfと同じ内容を持つ新しいハッシュを返します。

...selfと同じ内容を持つ新しいハッシュを返します。

clone は frozen singleton-class の情報も含めてコピーしますが、
dup は内容と tainted だけをコピーします。
またどちらのメソッドも要素それ自体のコピーはしません。
つまり参...
...//emlist[例][ruby]{
h1 = {"have" => "have a","as" => "as a" }
h2 = h1.dup

h2["have"] = "has"
p h2 #=> {"have"=>"has", "as"=>"as a"}
p h1 #=> {"have"=>"have a", "as"=>"as a"}

h2["as"].upcase!
p h2 #=> {"have"=>"has", "as"=>"AS A"}
p h1 #=> {"have"=>"have a", "as"=>"AS A"}
//}

@see Object#clone...
...selfと同じ内容を持つ新しいハッシュを返します。

clone は frozen singleton-class の情報も含めてコピーしますが、
dup は内容だけをコピーします。
またどちらのメソッドも要素それ自体のコピーはしません。
つまり参照してい...

Hash#dup -> Hash (15.0)

selfと同じ内容を持つ新しいハッシュを返します。

...selfと同じ内容を持つ新しいハッシュを返します。

clone は frozen singleton-class の情報も含めてコピーしますが、
dup は内容と tainted だけをコピーします。
またどちらのメソッドも要素それ自体のコピーはしません。
つまり参...
...//emlist[例][ruby]{
h1 = {"have" => "have a","as" => "as a" }
h2 = h1.dup

h2["have"] = "has"
p h2 #=> {"have"=>"has", "as"=>"as a"}
p h1 #=> {"have"=>"have a", "as"=>"as a"}

h2["as"].upcase!
p h2 #=> {"have"=>"has", "as"=>"AS A"}
p h1 #=> {"have"=>"have a", "as"=>"AS A"}
//}

@see Object#clone...
...selfと同じ内容を持つ新しいハッシュを返します。

clone は frozen singleton-class の情報も含めてコピーしますが、
dup は内容だけをコピーします。
またどちらのメソッドも要素それ自体のコピーはしません。
つまり参照してい...

Module#instance_method(name) -> UnboundMethod (15.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" => instance_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!
//}...

絞り込み条件を変える