ライブラリ
- ビルトイン (148)
- forwardable (12)
- psych (12)
モジュール
- Kernel (48)
キーワード
- != (12)
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) - << (14)
- === (12)
- >> (14)
-
NEWS for Ruby 2
. 1 . 0 (12) -
NEWS for Ruby 2
. 3 . 0 (10) -
NEWS for Ruby 2
. 7 . 0 (6) -
NEWS for Ruby 3
. 0 . 0 (5) - Rubyで使われる記号の意味(正規表現の複雑な記号は除く) (12)
- Ruby用語集 (12)
- SingleForwardable (12)
- clone (12)
- dup (12)
- fail (24)
-
instance
_ method (12) - raise (24)
-
ruby 1
. 6 feature (12) -
ruby 1
. 8 . 2 feature (12) -
ruby 1
. 8 . 4 feature (12) -
ruby 1
. 9 feature (12) -
test
/ unit (1) - yaml (12)
-
yaml
_ tag (12) - クラス/メソッドの定義 (12)
- パターンマッチ (9)
- メソッド呼び出し(super・ブロック付き・yield) (12)
- リテラル (12)
- 演算子式 (12)
検索結果
先頭5件
-
BasicObject
# ! -> bool (18137.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 (6106.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... -
ruby 1
. 6 feature (312.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
...)
: 2002-07-11 String#slice!
範囲外の文字列を指定したときに例外を返す場合がありましたが、常に nil
を返すようになりました。(String#[]やString#slice と同じ結果を返すと
いうことです)
p "foo".slice!("bar") # <- 以前から......こちらは nil を返していた
p "foo".slice!(5,10)
=> ruby 1.6.7 (2002-03-01) [i586-linux]
nil
-:2:in `slice!': index 5 out of string (IndexError)
from -:2
=> ruby 1.6.7 (2002-08-01) [i586-linux]
nil
nil
: 20......module_eval>)) のブロック内で定数やクラス変数のスコープが
変わることはなくなりました。((<ruby-dev:17876>))
class Foo
FOO = 1
@@foo = 1
end
FOO = 2
@@foo = 2
Foo.module_eval { p FOO, @@foo }
=... -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (288.0) -
1.6.8から1.8.0への変更点(まとめ) * ((<1.6.8から1.8.0への変更点(まとめ)/インタプリタの変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたクラス/モジュール>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加されたメソッド>)) * ((<1.6.8から1.8.0への変更点(まとめ)/追加された定数>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張されたクラス/メソッド(互換性のある変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/変更されたクラス/メソッド(互換性のない変更)>)) * ((<1.6.8から1.8.0への変更点(まとめ)/文法の変更>)) * ((<1.6.8から1.8.0への変更点(まとめ)/正規表現>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Marshal>)) * ((<1.6.8から1.8.0への変更点(まとめ)/Windows 対応>)) * ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>)) * ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>)) * ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>)) * ((<1.6.8から1.8.0への変更点(まとめ)/バグ修正>)) * ((<1.6.8から1.8.0への変更点(まとめ)/サポートプラットフォームの追加>))
...よくわかりません(^^;
class << Object
p [self.id, self]
class << self
p [self.id, self]
end
end
=> ruby 1.6.7 (2002-03-01) [i586-linux]
[537771634, Class]
[537742484, Class]
=> ruby 1.7.3 (2002-09......-05) [i586-linux]
[537771634, #<Class:Object>]
[537771634, #<Class:Object>]
さらに、オブジェクトの特異クラスのスーパークラスの特異クラスと
オブジェクトの特異クラスの特異クラスのスーパークラスは同じなのだそう......中だけになりました。
: rescue 節の例外クラスと発生した例外オブジェクトの比較 [ruby] [change]
発生した例外 $! と rescue 節の例外クラスとは ((<Module#===|Module/===>))
を使って比較するようになりました。
以前は kind_of? に... -
クラス/メソッドの定義 (264.0)
-
クラス/メソッドの定義 * クラス/メソッドの定義: * class * singleton_class * module * method * operator * nest_method * eval_method * singleton_method * class_method * limit * 定義に関する操作: * alias * undef * defined
...:
* class
* singleton_class
* module
* method
* operator
* nest_method
* eval_method
* singleton_method
* class_method
* limit
* 定義に関する操作:
* alias
* undef
* defined
===[a:class] クラス定義
//emlist[例][ruby]{
class Foo < S......uper
def test
# ...
end
# ...
end
//}
文法:
class 識別子 [`<' superclass ]
式..
end
文法:
class 識別子 [`<' superclass ]
式..
[rescue [error_type,..] [=> evar] [then]
式..]..
[else......の言語における「関数」のように使えます。
//emlist[例][ruby]{
def hello # 引数のないメソッド。
puts "Hello, world!"
end
def foo(a, b) # 引数のあるメソッド。括弧を省いてdef foo a, bとも
a + 3 * b
end
//}
メソッド名としては通常の... -
yaml (168.0)
-
構造化されたデータを表現するフォーマットであるYAML (YAML Ain't Markup Language) を扱うためのライブラリです。
...扱う事ができます。
=== タグの指定
!ruby/sym :foo などのようにタグを指定することで、読み込み時に記述した値
の型を指定できます。
//emlist[例][ruby]{
require 'yaml'
p YAML.load(<<~EOS)
---
!ruby/sym :foo
EOS
# => :foo
//}
yaml では、Ruby......* !ruby/array: Array オブジェクト
* !ruby/class: Class オブジェクト
* !ruby/hash: Hash オブジェクト
* !ruby/module: Module オブジェクト
* !ruby/regexp: Regexp オブジェクト
* !ruby/range: Range オブジェクト
* !ruby/string: String オブジェクト
* !ru......* !ruby/sym(もしくは !ruby/symbol): Symbol オブジェクト
* !ruby/encoding: Encoding オブジェクト
* !ruby/exception: 例外オブジェクト
* !ruby/object:<クラス名>: 上記以外のオブジェクト
//emlist[例][ruby]{
require 'yaml'
p YAML.load(<<~EOS)
---
array: !ru... -
リテラル (138.0)
-
リテラル * num * string * backslash * exp * char * command * here * regexp * array * hash * range * symbol * percent
...g] 文字列リテラル
//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)
"this is multi line
string"
//}
文字列はダブルクォートまたはシングルク......たびに新しい範囲オブジェクトを生
成します。
===[a:symbol] シンボル
//emlist[例][ruby]{
# (シンボルの例)
:class
:lvar
:method!
:andthisis?
:$gvar
:@ivar
:@@cvar
:+
//}
文法:
`:' 識別子
`:' 変数名
`:' 演算子
Symbolクラス......します。
* %!STRING! : ダブルクォート文字列
* %Q!STRING! : 同上
* %q!STRING! : シングルクォート文字列
* %x!STRING! : コマンド出力
* %r!STRING! : 正規表現
* %w!STRING! : 要素が文字列の配列(空白区切り)
* %W!STRING! : 要素が文字列... -
NEWS for Ruby 3
. 0 . 0 (114.0) -
NEWS for Ruby 3.0.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...d in singleton class definitions in methods is now a SyntaxError
instead of a warning. yield in a class definition outside of a method
is now a SyntaxError instead of a LocalJumpError. 15575
* When a class variable is overtaken by the same definition in an
ancestor class/module, a Run......timeError is now raised (previously,
it only issued a warning in verbose mode). Additionally, accessing a
class variable from the toplevel scope is now a RuntimeError.
14541
* Assigning to a numbered parameter is now a SyntaxError instead of
a warning.
== Command line options
==......race.
8661
== Core classes updates
Outstanding ones only.
* Array
* The following methods now return Array instances instead of subclass instances when called on subclass instances: 6087
* Array#drop
* Array#drop_while
* Array#flatten
* Array#slice!
* Array#sli... -
Kernel
. # fail(error _ type , message = nil , backtrace = caller(0) , cause: $ !) -> () (106.0) -
例外を発生させます。 発生した例外は変数 $! に格納されます。また例外が 発生した時のスタックトレースは変数 $@ に格納され ます。発生した例外は rescue 節で捕捉できます。
...例外を発生させます。
発生した例外は変数 $! に格納されます。また例外が
発生した時のスタックトレースは変数 $@ に格納され
ます。発生した例外は rescue 節で捕捉できます。
引数無しの場合は、同スレッドの同じブロ......ック内で最後に rescue された
例外オブジェクト ($!) を再発生させます。そのような
例外が存在しないが自身は捕捉されている時には例外 RuntimeError を発生させます。
//emlist[例][ruby]{
begin
open("nonexist")
rescue
raise #=> `open': N......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 MyException
def exception(mesg=ni...