別のキーワード
ライブラリ
- ビルトイン (682)
- abbrev (24)
- expect (24)
-
irb
/ cmd / help (12) - mkmf (24)
- pathname (88)
- rake (132)
-
rake
/ testtask (24) -
rdoc
/ markup (12) -
rinda
/ rinda (12) -
rinda
/ tuplespace (12) -
ripper
/ lexer (24) - rubygems (12)
-
rubygems
/ source _ index (12) -
rubygems
/ source _ info _ cache (24) - shell (6)
-
shell
/ builtin-command (6) -
shell
/ command-processor (6) -
shell
/ filter (6) - shellwords (12)
クラス
- Array (71)
- Dir (36)
- Enumerator (6)
-
Enumerator
:: Lazy (45) - File (24)
-
Gem
:: SourceIndex (12) -
Gem
:: SourceInfoCache (24) - IO (24)
-
IRB
:: ExtendCommand :: Help (12) - MatchData (4)
- Pathname (88)
-
RDoc
:: Markup (12) -
Rake
:: Application (12) -
Rake
:: FileList (96) -
Rake
:: TestTask (24) - Regexp (12)
-
Rinda
:: TupleSpace (12) -
Rinda
:: TupleSpaceProxy (12) - Ripper (24)
- Shell (6)
-
Shell
:: CommandProcessor (6) -
Shell
:: Filter (6) -
Shell
:: Glob (6) - String (282)
モジュール
- Abbrev (12)
- Enumerable (160)
- Gem (12)
- Kernel (84)
- Rake (12)
- Shellwords (12)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) -
DEFAULT
_ IGNORE _ PATTERNS (12) -
NEWS for Ruby 2
. 7 . 0 (6) -
NEWS for Ruby 3
. 0 . 0 (5) - NoMatchingPatternError (6)
-
WIN
_ PATTERNS (12) - [] (12)
- abbrev (24)
-
add
_ special (12) - all? (45)
- any? (48)
- application= (12)
- byteindex (3)
- byterindex (3)
- captures (2)
- deconstruct (2)
- egrep (12)
-
egrep
_ cpp (24) - exclude (12)
- execute (12)
- expect (24)
- fnmatch (24)
- fnmatch? (24)
- glob (82)
- grep (36)
-
grep
_ v (34) - gsub (96)
- gsub! (60)
- index (12)
- irb (12)
- new (18)
- none? (15)
- notify (24)
- one? (15)
-
pathmap
_ replace (12) - pattern= (12)
- produce (6)
- rake (12)
- rdoc (12)
- rindex (12)
-
ruby 1
. 8 . 4 feature (12) - scan (24)
- search (24)
-
search
_ with _ source (12) - shellescape (12)
- slice (12)
-
slice
_ after (35) -
slice
_ before (36) - sub (96)
- sub! (48)
-
token
_ match (12) - tr (12)
- tr! (12)
-
tr
_ s (12) -
tr
_ s! (12) - union (12)
- パターンマッチ (12)
- 制御構造 (12)
- 正規表現 (12)
検索結果
先頭5件
-
パターンマッチ (6208.0)
-
パターンマッチ * patterns * variable_binding * variable_pinning * matching_non_primitive_objects * guard_clauses * current_feature_status * pattern_syntax * some_undefined_behavior_examples
...パターンマッチ
* patterns
* variable_binding
* variable_pinning
* matching_non_primitive_objects
* guard_clauses
* current_feature_status
* pattern_syntax
* some_undefined_behavior_examples
パターンマッチは、構造化された値に対して、構造をチェック......チは in 演算子を用いて実装されており、単体の式や
<expression> in <pattern>
case 文の中で利用できます。
case <expression>
in <pattern1>
...
in <pattern2>
...
in <pattern3>
...
else
...
end
in 節と when 節は1つの case 式の中......ッチせず else 節がない場合、例外 NoMatchingPatternError が発生します。
そのため、条件付きのマッチや展開に case 式が使われることがあります。
//emlist[][ruby]{
config = {db: {user: 'admin', password: 'abc123'}}
case config
in db: {user:} # ネス... -
Rake
:: FileList # egrep(pattern) {|filename , count , line| . . . } (6207.0) -
与えられたパターンをファイルリストから grep のように検索します。
...与えられたパターンをファイルリストから grep のように検索します。
ブロックが与えられた場合は、マッチした行の情報 (ファイル名、行番号、マッチした行) が
ブロックに渡されてブロックが評価されます。ブロックが......。
@param pattern 正規表現を指定します。
//emlist[][ruby]{
# Rakefile での記載例とする
IO.write("sample1", "line1\nline2\nline3\n")
IO.write("sample2", "line1\nline2\nline3\nline4\n")
task default: :test_rake_app
task :test_rake_app do
file_list = FileList.new('sample*')......file_list.egrep(/line/) # => 7
file_list.egrep(/.*/) do |filename, count, line|
"filename = #{filename}, count = #{count}, line = #{line}"
end
end
# => "filename = sample1, count = 1, line = line1\n"
# => "filename = sample1, count = 2, line = line2\n"
# => "filename = sample1, count = 3,... -
Enumerator
:: Lazy # grep(pattern) {|item| . . . } -> Enumerator :: Lazy (6201.0) -
Enumerable#grep と同じですが、配列ではなくEnumerator::Lazy を返します。
...rep と同じですが、配列ではなくEnumerator::Lazy を返します。
//emlist[例][ruby]{
(100..Float::INFINITY).lazy.map(&:to_s).grep(/\A(\d)\1+\z/)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 100..Infinity>:map>:grep(/\A(\d)\1+\z/)>
(100..Float::INFINITY).lazy.map(&......:to_s).grep(/\A(\d)\1+\z/).take(10).force
# => ["111", "222", "333", "444", "555", "666", "777", "888", "999", "1111"]
//}
@see Enumerable#grep......:to_s).grep(/\A(\d)\1+\z/).take(10).force
# => ["111", "222", "333", "444", "555", "666", "777", "888", "999", "1111"]
//}
@see Enumerable#grep, Enumerable#grep_v, Enumerator::Lazy#grep_v... -
Enumerator
:: Lazy # grep _ v(pattern) {|item| . . . } -> Enumerator :: Lazy (6201.0) -
Enumerable#grep_v と同じですが、配列ではなくEnumerator::Lazy を返します。
...rep_v と同じですが、配列ではなくEnumerator::Lazy を返します。
//emlist[例][ruby]{
(100..Float::INFINITY).lazy.map(&:to_s).grep_v(/(\d).*\1/)
# => #<Enumerator::Lazy: #<Enumerator::Lazy: #<Enumerator::Lazy: 100..Infinity>:map>:grep_v(/(\d).*\1/)>
(100..Float::INFINITY).lazy.map(&......:to_s).grep_v(/(\d).*\1/).take(15).force
# => ["102", "103", "104", "105", "106", "107", "108", "109", "120", "123", "124", "125", "126", "127", "128"]
//}
@see Enumerable#grep_v, Enumerable#grep, Enumerator::Lazy#grep... -
MatchData
# captures -> [String] (6118.0) -
$1, $2, ... を格納した配列を返します。
...応する要素は nil になります。
//emlist[例][ruby]{
/(foo)(bar)(BAZ)?/ =~ "foobarbaz"
p $~.to_a # => ["foobar", "foo", "bar", nil]
p $~.captures # => ["foo", "bar", nil]
//}
@see MatchData#to_a, MatchData#named_captures, d:spec/pattern_matching#matching_non_primitive_objects... -
Rake
:: Application # options -> OpenStruct (6112.0) -
コマンドラインで与えられたアプリケーションのオプションを返します。
...ake_app
task :test_rake_app do
Rake.application.options # => #<OpenStruct always_multitask=false, backtrace=false, build_all=false, dryrun=false, ignore_deprecate=false, ignore_system=false, job_stats=false, load_system=false, nosearch=false, rakelib=["rakelib"], show_all_tasks=false, show_prereq......s=false, show_task_pattern=nil, show_tasks=nil, silent=false, suppress_backtrace_pattern=nil, thread_pool_size=8, trace=false, trace_output=#<IO:<STDERR>>, trace_rules=false>
end
//}... -
Shellwords
. # shellescape(str) -> String (6112.0) -
文字列を Bourne シェルのコマンドライン中で安全に使えるようにエスケープします。
...ープします。
@param str エスケープの対象となる文字列を指定します。
@return エスケープされた文字列を返します。
例:
require 'shellwords'
pattern = 'Jan 15'
puts "grep #{Shellwords.shellescape(pattern)} file"
# => grep Jan\ 15 file... -
Ripper
. token _ match(src , pattern) -> Ripper :: TokenPattern :: MatchData | nil (3417.0) -
Ruby プログラム src に対してパターン pattern をマッチし、 マッチデータを返します。
...Ruby プログラム src に対してパターン pattern をマッチし、
マッチデータを返します。
ライブラリ内部で使用します。... -
Regexp
. union(*pattern) -> Regexp (3329.0) -
引数として与えた pattern を選択 | で連結し、Regexp として返します。 結果の Regexp は与えた pattern のどれかにマッチする場合にマッチするものになります。
...引数として与えた pattern を選択 | で連結し、Regexp として返します。
結果の Regexp は与えた pattern のどれかにマッチする場合にマッチするものになります。
//emlist[][ruby]{
p Regexp.union(/a/, /b/, /c/) # => /(?-mix:a)|(?-mix:b)|(?-mix:c)/
//}......を与えても Regexp を生成します。
つまり、以下のように書くことができます。
//emlist[][ruby]{
arr = [/a/, /b/, /c/]
p Regexp.union(arr) # => /(?-mix:a)|(?-mix:b)|(?-mix:c)/
# 1.8.7 より前は、以下のように書く必要があった
p Regexp.union(*arr) # => /(?......//}
pattern は Regexp または String で与えます。
String で与えた場合、それ自身と等しい文字列にマッチするものと解釈され、
エスケープされて結果の Regexp に組み込まれます。
//emlist[][ruby]{
p Regexp.union("a", "?", "b") # => /a|\?|b/
p Re... -
Pathname
# sub(pattern) {|matched| . . . } -> Pathname (3314.0) -
self を表現するパス文字列に対して sub メソッドを呼び出し、その結果を内 容とする新しい Pathname オブジェクトを生成し、返します。
...しい Pathname オブジェクトを生成し、返します。
@param pattern 置き換える文字列のパターンを指定します。
@param replace pattern で指定した文字列と置き換える文字列を指定します。
//emlist[例][ruby]{
require 'pathname'
path1 = Pathname('/......usr/bin/perl')
path1.sub('perl', 'ruby') #=> #<Pathname:/usr/bin/ruby>
//}
@see String#sub...