種類
- 文書 (29)
- インスタンスメソッド (24)
ライブラリ
- ビルトイン (24)
クラス
- Object (24)
キーワード
-
NEWS for Ruby 2
. 5 . 0 (7) -
NEWS for Ruby 2
. 6 . 0 (6) -
NEWS for Ruby 2
. 7 . 0 (5) -
yield
_ self (12) - 制御構造 (11)
検索結果
先頭5件
-
Object
# then -> Enumerator (18114.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...self を引数としてブロックを評価し、ブロックの結果を返します。
//emlist[例][ruby]{
3.next.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}
値をメソッドチェインのパイプラインに次々と渡すの......ライン][ruby]{
require 'open-uri'
require 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使... -
Object
# then {|x| . . . } -> object (18114.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...self を引数としてブロックを評価し、ブロックの結果を返します。
//emlist[例][ruby]{
3.next.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}
値をメソッドチェインのパイプラインに次々と渡すの......ライン][ruby]{
require 'open-uri'
require 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使... -
Object
# yield _ self -> Enumerator (3014.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...self を引数としてブロックを評価し、ブロックの結果を返します。
//emlist[例][ruby]{
3.next.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}
値をメソッドチェインのパイプラインに次々と渡すの......ライン][ruby]{
require 'open-uri'
require 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使... -
Object
# yield _ self {|x| . . . } -> object (3014.0) -
self を引数としてブロックを評価し、ブロックの結果を返します。
...self を引数としてブロックを評価し、ブロックの結果を返します。
//emlist[例][ruby]{
3.next.then {|x| x**x }.to_s # => "256"
"my string".yield_self {|s| s.upcase } # => "MY STRING"
//}
値をメソッドチェインのパイプラインに次々と渡すの......ライン][ruby]{
require 'open-uri'
require 'json'
construct_url(arguments).
yield_self {|url| URI(url).read }.
yield_self {|response| JSON.parse(response) }
//}
ブロックなしで呼び出されたときは Enumerator を返します。
例えば条件によって値を捨てるのに使... -
制御構造 (84.0)
-
制御構造 条件分岐: * if * unless * case 繰り返し: * while * until * for * break * next * redo * retry 例外処理: * raise * begin その他: * return * BEGIN * END
...===[a:if] if
//emlist[例][ruby]{
if age >= 12 then
print "adult fee\n"
else
print "child fee\n"
end
gender = if foo.gender == "male" then "male" else "female" end
//}
文法:
if 式 [then]
式 ...
[elsif 式 [then]
式 ... ]
.........[else
式 ... ]
end
条件式を評価した結果が真である時、then 以下の式を評価します。
if の条件式が偽であれば elsif の条件を評価します。
elsif 節は複数指定でき、全ての if および elsif
の条件式が偽であったと......ります。
メソッドの引数にするには二重の括弧が必要です。
p(open("nonexistent file") rescue false)
=> parse error
p((open("nonexistent file") rescue false))
=> false
=== その他
====[a:return] return
//emlist[例][ruby]{
return... -
NEWS for Ruby 2
. 7 . 0 (42.0) -
NEWS for Ruby 2.7.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...p var #=> 1
end
//}
//emlist[][ruby]{
case -1
in 0 then :unreachable
in 1 then :unreachable
end #=> NoMatchingPatternError
//}
//emlist{
json = <<END
{
"name": "Alice",
"age": 30,
"children": [{ "name": "Bob", "age": 2 }]
}
END
JSON.parse(json, symbolize_names: true) in {name: "Alice", chi......ldren: [{name: name, age: age}]}
p name #=> "Bob"
p age #=> 2
JSON.parse(json, symbolize_names: true) in {name: "Alice", children: [{name: "Charlie", age: age}]}
#=> NoMatchingPatternError
//}
* 詳細は https://speakerdeck.com/k_tsj/pattern-matching-new-feature-in-ruby-2-dot-7 のスライ......定数やDSLなどで便利かもしれません。
14799
//emlist[][ruby]{
ary[..3] # identical to ary[0..3]
case RUBY_VERSION
when ..."2.4" then puts "EOL"
# ...
end
age.clamp(..100)
where(sales: ..100)
//}
* 「$;」にnil以外の値を設定すると警告が出るようになりま... -
NEWS for Ruby 2
. 5 . 0 (30.0) -
NEWS for Ruby 2.5.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...result
#=> { "/path/to/file.rb"=>
# { :lines => [1, 2, 0, nil, ...],
# :branches =>
# { [:if, 0, 2, 1, 6, 4] =>
# { [:then, 1, 3, 2, 3, 8] => 0,
# [:else, 2, 5, 2, 5, 8] => 2
# }
# },
# :methods => {
# [Object, :foo, 1, 0......と読みます。
[:then, 1, 3, 2, 3, 8] は、then節が3行目の2桁目から3行目の8桁目まで、と読みます。
なお、行番号は1から始まり、桁番号は0から始まります。
よって、上記の例ではifから最初のthen節は実行されておら......n to a keyword argument
https://github.com/ruby/psych/pull/342
* Add :symbolize_names option to Psych.load, Psych.safe_load like JSON.parse
https://github.com/ruby/psych/pull/333, https://github.com/ruby/psych/pull/337
* Add Psych::Handler#event_location
https://g... -
NEWS for Ruby 2
. 6 . 0 (24.0) -
NEWS for Ruby 2.6.0 このドキュメントは前回リリース以降のバグ修正を除くユーザーに影響のある機能の変更のリストです。
...ン
* 排他的ファイルオープンを表すモード文字 'x' が追加されました。 11258
* Kernel
* 別名
* Object#then が Object#yield_self の別名として追加されました。 14594
* 新規オプション
* Kernel.#Complex, Kernel.#Float, Kernel.#......* RubyVM::AbstractSyntaxTree
* 新規メソッド
* RubyVM::AbstractSyntaxTree.parse は文字列をパースして AST ノードを返します。 [実験的]
* RubyVM::AbstractSyntaxTree.parse_file はファイルをパースして AST ノードを返します。 [実験的]......name(#{NODE_SET})" の問題
* RSS
* 新規オプション
* RSS::Parser.parse が Hash としてオプションを受け付けるようになりました。
:validate, :ignore_unknown_element, :parser_class オプションが利用可能です。
* RubyGems
* RubyGems 3....