種類
- 文書 (128)
- モジュール関数 (44)
- インスタンスメソッド (44)
- モジュール (11)
- ライブラリ (1)
ライブラリ
- ビルトイン (88)
- forwardable (11)
クラス
- BasicObject (22)
- Module (11)
- Object (11)
モジュール
- Kernel (44)
キーワード
- != (11)
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - === (11)
-
NEWS for Ruby 2
. 1 . 0 (11) -
NEWS for Ruby 2
. 3 . 0 (9) -
NEWS for Ruby 2
. 7 . 0 (5) -
NEWS for Ruby 3
. 0 . 0 (4) - Ruby用語集 (11)
- SingleForwardable (11)
- fail (22)
-
instance
_ method (11) - raise (22)
-
ruby 1
. 6 feature (11) -
ruby 1
. 8 . 2 feature (11) -
ruby 1
. 8 . 4 feature (11) -
ruby 1
. 9 feature (11) -
test
/ unit (1) - メソッド呼び出し(super・ブロック付き・yield) (11)
- リテラル (11)
- 演算子式 (11)
検索結果
先頭5件
-
BasicObject
# ! -> bool (21137.0) -
オブジェクトを真偽値として評価し、その論理否定を返します。
...lf が nil または false であれば真を、さもなくば偽を返します。
主に論理式の評価に伴って副作用を引き起こすことを目的に
再定義するものと想定されています。
このメソッドを再定義しても Ruby の制御式において nil や fa......ist[例][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......AnotherFalse < 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 (9106.0) -
オブジェクトが other と等しくないことを判定します。
...理否定して返します。
このため、サブクラスで BasicObject#== を再定義しても != とは自動的に整合性が
とれるようになっています。
ただし、 BasicObject#!= 自身や BasicObject#! を再定義した際には、ユーザーの責任で
整合性を保......ト
@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... -
Kernel
. # fail(error _ type , message = nil , backtrace = caller(0) , cause: $ !) -> () (6306.0) -
例外を発生させます。 発生した例外は変数 $! に格納されます。また例外が 発生した時のスタックトレースは変数 $@ に格納され ます。発生した例外は rescue 節で捕捉できます。
...例外を発生させます。
発生した例外は変数 $! に格納されます。また例外が
発生した時のスタックトレースは変数 $@ に格納され
ます。発生した例外は rescue 節で捕捉できます。
引数無しの場合は、同スレッドの同じブロ......ジェクト ($!) を再発生させます。そのような
例外が存在しないが自身は捕捉されている時には例外 RuntimeError を発生させます。
//emlist[例][ruby]{
begin
open("nonexist")
rescue
raise #=> `open': No such file or directory - "nonexist" (Errno::ENOEN....../emlist[例2][ruby]{
def foo num
print 'in method.'
raise "error!!" if num <= 9
rescue RuntimeError
num += 10
print 'in rescue.'
retry
else
print 'in else.'
ensure
print "in ensure.\n"
end
foo(4) #=> in method.in rescue.in method.in else.in ensure.
//}
//emlist[例3][ruby]{
class MyE... -
Kernel
. # fail(message , cause: $ !) -> () (6206.0) -
例外を発生させます。 発生した例外は変数 $! に格納されます。また例外が 発生した時のスタックトレースは変数 $@ に格納され ます。発生した例外は rescue 節で捕捉できます。
...例外を発生させます。
発生した例外は変数 $! に格納されます。また例外が
発生した時のスタックトレースは変数 $@ に格納され
ます。発生した例外は rescue 節で捕捉できます。
引数無しの場合は、同スレッドの同じブロ......ジェクト ($!) を再発生させます。そのような
例外が存在しないが自身は捕捉されている時には例外 RuntimeError を発生させます。
//emlist[例][ruby]{
begin
open("nonexist")
rescue
raise #=> `open': No such file or directory - "nonexist" (Errno::ENOEN....../emlist[例2][ruby]{
def foo num
print 'in method.'
raise "error!!" if num <= 9
rescue RuntimeError
num += 10
print 'in rescue.'
retry
else
print 'in else.'
ensure
print "in ensure.\n"
end
foo(4) #=> in method.in rescue.in method.in else.in ensure.
//}
//emlist[例3][ruby]{
class MyE... -
Kernel
. # raise(error _ type , message = nil , backtrace = caller(0) , cause: $ !) -> () (6206.0) -
例外を発生させます。 発生した例外は変数 $! に格納されます。また例外が 発生した時のスタックトレースは変数 $@ に格納され ます。発生した例外は rescue 節で捕捉できます。
...例外を発生させます。
発生した例外は変数 $! に格納されます。また例外が
発生した時のスタックトレースは変数 $@ に格納され
ます。発生した例外は rescue 節で捕捉できます。
引数無しの場合は、同スレッドの同じブロ......ジェクト ($!) を再発生させます。そのような
例外が存在しないが自身は捕捉されている時には例外 RuntimeError を発生させます。
//emlist[例][ruby]{
begin
open("nonexist")
rescue
raise #=> `open': No such file or directory - "nonexist" (Errno::ENOEN....../emlist[例2][ruby]{
def foo num
print 'in method.'
raise "error!!" if num <= 9
rescue RuntimeError
num += 10
print 'in rescue.'
retry
else
print 'in else.'
ensure
print "in ensure.\n"
end
foo(4) #=> in method.in rescue.in method.in else.in ensure.
//}
//emlist[例3][ruby]{
class MyE... -
Kernel
. # raise(message , cause: $ !) -> () (6206.0) -
例外を発生させます。 発生した例外は変数 $! に格納されます。また例外が 発生した時のスタックトレースは変数 $@ に格納され ます。発生した例外は rescue 節で捕捉できます。
...例外を発生させます。
発生した例外は変数 $! に格納されます。また例外が
発生した時のスタックトレースは変数 $@ に格納され
ます。発生した例外は rescue 節で捕捉できます。
引数無しの場合は、同スレッドの同じブロ......ジェクト ($!) を再発生させます。そのような
例外が存在しないが自身は捕捉されている時には例外 RuntimeError を発生させます。
//emlist[例][ruby]{
begin
open("nonexist")
rescue
raise #=> `open': No such file or directory - "nonexist" (Errno::ENOEN....../emlist[例2][ruby]{
def foo num
print 'in method.'
raise "error!!" if num <= 9
rescue RuntimeError
num += 10
print 'in rescue.'
retry
else
print 'in else.'
ensure
print "in ensure.\n"
end
foo(4) #=> in method.in rescue.in method.in else.in ensure.
//}
//emlist[例3][ruby]{
class MyE... -
Module
# instance _ method(name) -> UnboundMethod (6112.0) -
self のインスタンスメソッド name をオブジェクト化した UnboundMethod を返します。
...tring で指定します。
@raise NameError self に存在しないメソッドを指定した場合に発生します。
@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() prin......t "!\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
e......nd
interpreter = Interpreter.new
interpreter.interpret('dave')
# => Hello there, Dave!
//}... -
test
/ unit (6018.0) -
ユニットテストを行うためのライブラリです。
...してください。
* Test::Unit - Ruby用単体テストフレームワーク: https://test-unit.github.io/
なお、2.2.0より前のtest/unit は当時バンドルしていた minitest/unit を使って再実装し
ていましたが、上記のtest/unitと完全な互換性がある訳で......om/blog/2014/11/6.html
* RubyKaigi 2015:The history of testing framework in Ruby https://www.clear-code.com/blog/2015/12/12.html
=== 使い方
Test::Unit は以下のように使います。
まずテスト対象のソース(foo.rb)が必要です。
class Foo
def foo
"fo......。
: Failure
アサーションに失敗した。
=== 並列実行
1.9.3 から単体テストの高速化のために、並列実行がサポートされました。
並列化の仕組みについては以下の記事をご覧ください。
* Rubyist Magazine 0033 号 詳解! test-all 並... -
SingleForwardable (6012.0)
-
オブジェクトに対し、メソッドの委譲機能を定義するモジュールです。
...require 'forwardable'
g = Goo.new
g.extend SingleForwardable
g.def_delegator("@out", :puts)
g.puts ...
また、SingleForwardable はクラスやモジュールに対して以下のようにする事もできます。
require 'forwardable'
class Implementation
def self.service......puts "serviced!"
end
end
module Facade
extend SingleForwardable
def_delegator :Implementation, :service
end
Facade.service # => serviced!
もし Forwardable と SingleForwardable の両方を使いたい場合、
def_instance_delegator と def_single_delegator メソッ... -
リテラル (3210.0)
-
リテラル * num * string * backslash * exp * char * command * here * regexp * array * hash * range * symbol * percent
...リテラル
* num
* string
* backslash
* exp
* char
* command
* here
* regexp
* array
* hash
* range
* symbol
* percent
数字の1や文字列"hello world"のようにRubyのプログラムの中に直接
記述できる値の事をリテラルといいます。
===[a:n......//emlist[][ruby]{
1_000_000_000 # => 1000000000
0xffff_ffff # => 0xffffffff
//}
===[a:string] 文字列リテラル
//emlist[例][ruby]{
"this is a string expression\n"
'this is a string expression\n'
%q!I said, "You said, 'She said it.'"!
%!I said, "You said, 'She said it.'"!
%Q('This is it.'\n......されるたびに新しい範囲オブジェクトを生
成します。
===[a:symbol] シンボル
//emlist[例][ruby]{
# (シンボルの例)
:class
:lvar
:method!
:andthisis?
:$gvar
:@ivar
:@@cvar
:+
//}
文法:
`:' 識別子
`:' 変数名
`:' 演算子
Symbol...