種類
- 文書 (77)
- モジュール関数 (11)
- インスタンスメソッド (11)
- 変数 (11)
ライブラリ
- ビルトイン (33)
クラス
- Regexp (11)
モジュール
- Kernel (22)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - Rubyで使われる記号の意味(正規表現の複雑な記号は除く) (11)
- print (11)
-
ruby 1
. 6 feature (11) -
ruby 1
. 8 . 2 feature (11) -
ruby 1
. 8 . 3 feature (11) - ~ (11)
- クラス/メソッドの定義 (11)
- 制御構造 (11)
検索結果
-
Kernel
$ $ _ -> String | nil (18236.0) -
最後に Kernel.#gets または Kernel.#readline で読み込んだ文字列です。 EOF に達した場合には、 nil になります。 (覚え方: Perlと同じ)
... nil になります。
(覚え方: Perlと同じ)
Kernel.#print のような Perl 由来の幾つかのメソッドは、引数を省略すると代わりに $_ を利用します。
この変数はローカルスコープかつスレッドローカルです。
Ruby起動時の初期値は nil......RGF
=== 例
example.txt:
foo
bar
baz
このとき、コマンド ruby -e 'print while gets' example.txt は次を出力します
foo
bar
baz
ただし、このプログラムは次のように書く方がよりRuby的です。
//emlist[例][ruby]{
ARGF.each do |line|
print line
end
//}... -
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (1242.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への変更点(まとめ)/サポートプラットフォームの追加>))
...りました。
* nil: 警告を出力しない (-W0 新しい警告レベル)
* false: 重要な警告のみ出力 (-W1 デフォルト)
* true: すべての警告を出力する (-W2 or -W or -v or -w or --verbose)
追加された -W オプションは $VERBOSE = nil の指定(-W0)を......よくわかりません(^^;
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......件式中の正規表現リテラル [parser] [change]
条件式中の正規表現リテラルは警告が出るようになりました。
$_ との正規表現マッチは、明示的に ~/re/ (単項の ((<Regexp/~>)) メソッ
ド)などとすることが推奨されます。
== 正... -
クラス/メソッドの定義 (672.0)
-
クラス/メソッドの定義 * クラス/メソッドの定義: * class * singleton_class * module * method * operator * nest_method * eval_method * singleton_method * class_method * limit * 定義に関する操作: * alias * undef * defined
...fined
===[a:class] クラス定義
//emlist[例][ruby]{
class Foo < Super
def test
# ...
end
# ...
end
//}
文法:
class 識別子 [`<' superclass ]
式..
end
文法:
class 識別子 [`<' superclass ]
式..
[rescue [erro......返さない場合は nil を返します。
===[a:singleton_class] 特異クラス定義
//emlist[例][ruby]{
obj = Object.new # obj = nil でも可
class << obj
def test
# ...
end
# ...
end
//}
文法:
class `<<' expr
式..
end
文法:
clas......ことを意
味します。
//emlist[][ruby]{
# 特殊な変数のエイリアスは一方の変更が他方に反映される
$_ = 1
alias $foo $_
$_ = 2
p [$foo, $_] # => [2, 2]
$bar = 3
alias $foo $bar
$bar = 4
p [$foo, $bar] # => [4, 4]
//}
ただし、正規表現の部分文字列に対... -
ruby 1
. 6 feature (576.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
... nil
を返すようになりました。(String#[]やString#slice と同じ結果を返すと
いうことです)
p "foo".slice!("bar") # <- 以前からこちらは nil を返していた
p "foo".slice!(5,10)
=> ruby 1.6.7 (2002-03-01) [i586-linux]
nil......ーになっていました。
((<ruby-dev:17155>))
open("|-","r+") {|f|
if f
f.dup.close_write
else
sleep 1
end
}
=> ruby 1.6.7 (2002-03-01) [i586-linux]
-:3:in `close_write': closing non-duplex IO for writing (IOError)
from -:3......の状態をクリアしていませんでした。
((<ruby-bugs-ja:PR#208>))
/foo/ =~ "foo"
/foo/ =~ nil
p $~
/foo/ =~ "foo"
$_ = nil; ~"foo"
p $~
/foo/ =~ "foo"
"foo".index(/bar/, 4)
p $~
/foo/ =~ "foo"... -
制御構造 (544.0)
-
制御構造 条件分岐: * if * unless * case 繰り返し: * while * until * for * break * next * redo * retry 例外処理: * raise * begin その他: * return * BEGIN * END
...* until
* for
* break
* next
* redo
* retry
例外処理:
* raise
* begin
その他:
* return
* BEGIN
* END
Rubyでは(Cなどとは異なり)制御構造は式であって、何らかの値を返すものが
あります(返さないものもありま......節)の最後に評価し
た式の結果を返します。else 節がなくいずれの条件も成り立たなけれ
ば nil を返します。
Ruby では false または nil だけが偽で、それ以外は 0 や空文
字列も含め全て真です。
Ruby では if を繋げるのは elsif......)でもないことに注意してください。
また if の条件式が正規表現のリテラルである時には特別に
//emlist[][ruby]{
$_ =~ リテラル
//}
であるかのように評価されます。
==== if 修飾子
//emlist[例][ruby]{
print "debug\n" if $DEBUG
//}
文法:... -
Kernel
. # print(*arg) -> nil (143.0) -
引数を順に標準出力 $stdout に出力します。引数が与えられない時には変数 $_ の値を出力します。
...れない時には変数
$_ の値を出力します。
文字列以外のオブジェクトが引数として与えられた場合には、
to_s メソッドにより文字列に変換してから出力します。
変数 $, (出力フィールドセパレータ)に nil で
ない値がセット......されている時には、各引数の間にその文字列を出力します。
変数 $\ (出力レコードセパレータ)に nil でな
い値がセットされている時には、最後にそれを出力します。
@param arg 出力するオブジェクトを任意個指定します。
@ra......た場合に発生します。
//emlist[例][ruby]{
print "Hello, world!"
print "Regexp is",/ant/
print nil
print "\n"
#=> Hello, world!Regexp is(?-mix:ant)
$_ = "input"
$, = "<and>"
$\ = "<end>\n"
print
print "AA","BB"
#=> input<end>
#=> AA<and>BB<end>
//}
@see Kernel.#puts,Kernel.#p,IO#print... -
Regexp
# ~ -> Integer | nil (137.0) -
変数 $_ の値との間でのマッチをとります。
...変数 $_ の値との間でのマッチをとります。
ちょうど以下と同じ意味です。
//emlist[][ruby]{
self =~ $_
//}
//emlist[例][ruby]{
$_ = "hogehoge"
if /foo/
puts "match"
else
puts "no match"
end
# => no match
# ただし、警告がでる。warning: regex literal in......condition
reg = Regexp.compile("foo")
if ~ reg
puts "match"
else
puts "no match"
end
# => no match
if reg
puts "match"
else
puts "no match"
end
# => match
# reg は nil でも false でも無いので常にtrue
//}... -
ruby 1
. 8 . 2 feature (132.0) -
ruby 1.8.2 feature ruby 1.8.2 での ruby 1.8.1 からの変更点です。
...子以外では nil を 0 に変換しなくなりました。
$ ruby-1.8.1 -e 'p [nil].pack("L")'
"\000\000\000\000"
$ ruby-1.8.2 -e 'p [nil].pack("L")'
-e:1:in `pack': cannot convert nil into Integer (TypeError)
from -e:1
$ ruby-1.8.2 -e 'p [nil].pack("P")'......]
セッションを保存するファイル名にセッション ID が使われるバグを修正しました。
=== 2004-08-23
: OpenSSL::SSL#pending [lib] [new]
=== 2004-08-14
: FileUtils.copy_entry [lib] [new]
: FileUtils::DryRun [lib] [new]
追加。
: FileUtils.mv [lib] [compat]
mv......23690>))
$ ruby1.8.1 -e 'class X;end; x=X.new; class << x;p self < X; end'
true
$ ruby1.8.2 -e 'class X;end; x=X.new; class << x;p self < X; end'
nil
=== 2004-06-04
: IO#gets, $_ [ruby] [change]
gets の返り値が nil でも、$_ に nil がセットされるようになり... -
ruby 1
. 8 . 3 feature (108.0) -
ruby 1.8.3 feature *((<ruby 1.8 feature>)) *((<ruby 1.8.2 feature>))
...た。
$ cat mthd_taint.rb
th = Thread.new{
$SAFE = 3
class Hoge
def foo
puts "safe level: #{$SAFE}"
end
end
}
th.join
p $SAFE
Hoge.new.foo
$ ruby-1.8.2 mthd_taint.rb
0
"safe level: 0"
$ ruby-1.8.3 mthd_ta......オプションに -w を付けた時に出ます。((<ruby-dev:26201>))
=== 2005-05-22
: OpenSSL::SSL::SSLServer#initialize(svr, ctx, session_id=nil)
session_id を受け付けるようになりました。((<ruby-core:4663>))
=== 2005-05-19
: REXML::Encoding#decode_sjis [lib] [bug]
: REXML::......oo-bar
$_foo_bar
$ ruby-1.8.3 -se 'puts global_variables.grep(/foo/)' -- --foo\@bar
-e: invalid name for global variable - --foo@bar (NameError)
=== 2005-04-18
: WIN32OLE.codepage [lib] [new]
: WIN32OLE.codepage= [lib] [new]
=== 2005-04-10
: WIN32OLE#invoke [lib] [bug]
nil を V... -
Rubyで使われる記号の意味(正規表現の複雑な記号は除く) (72.0)
-
Rubyで使われる記号の意味(正規表現の複雑な記号は除く) ex q num per and or plus minus ast slash hat sq period comma langl rangl eq tilde dollar at under lbrarbra lbra2rbra2 lbra3rbra3 dq colon ac backslash semicolon
...ソッドを示すために使われます。
: xx ? yy : zz
d:spec/operator#cond。三項演算子とも呼ばれます。if xx then yy else zz end と同じ意味です。
: /xxx?/
正規表現の、量指定子(quantifiers)。直前の正規表現の 0 または 1 回の繰り返し。
===......をブロックとして使う。d:spec/call#block を参照。
: xxx&.yyy
safe navigation operator(通称「ぼっち演算子」)。xxx が nil でないときにメソッドyyyを呼び出す。spec/call を参照。
===[a:or] |
: 3 | 5
論理和演算子または類似のメソッド......チが失敗したらtrueを返します。
: ~ /xxx/
/xxx/ =~ $_ の省略形。~の後ろは正規表現でなければいけません。
===[a:dollar] $
: $xxx
グローバル変数。d:spec/variables#globalを参照。
: $_ や $! など ・・$<1文字の数字、記号>
特殊変数(...