ruri 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +20 -0
- data/README.md +50 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/bin/ruri +4 -0
- data/lib/ruri.rb +3 -0
- data/lib/ruri/search.rb +117 -0
- data/lib/ruri/util.rb +28 -0
- data/spec/fixtures/search_result.html +1303 -0
- data/spec/ruri/search_spec.rb +47 -0
- data/spec/ruri_spec.rb +5 -0
- data/spec/spec_helper.rb +16 -0
- metadata +237 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
gem 'cinatra'
|
7
|
+
gem 'nokogiri'
|
8
|
+
|
9
|
+
# Add dependencies to develop your gem here.
|
10
|
+
# Include everything needed to run rake, tests, features, etc.
|
11
|
+
group :development do
|
12
|
+
gem "rspec", "~> 2.3.0"
|
13
|
+
gem "rr", "~> 1.0.2"
|
14
|
+
gem "bundler", "~> 1.0.0"
|
15
|
+
gem "jeweler", "~> 1.5.2"
|
16
|
+
gem "rcov", ">= 0"
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
cinatra (0.5.0)
|
5
|
+
diff-lcs (1.1.2)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.5.2)
|
8
|
+
bundler (~> 1.0.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
nokogiri (1.4.4)
|
12
|
+
rake (0.8.7)
|
13
|
+
rcov (0.9.9)
|
14
|
+
rr (1.0.2)
|
15
|
+
rspec (2.3.0)
|
16
|
+
rspec-core (~> 2.3.0)
|
17
|
+
rspec-expectations (~> 2.3.0)
|
18
|
+
rspec-mocks (~> 2.3.0)
|
19
|
+
rspec-core (2.3.1)
|
20
|
+
rspec-expectations (2.3.0)
|
21
|
+
diff-lcs (~> 1.1.2)
|
22
|
+
rspec-mocks (2.3.0)
|
23
|
+
|
24
|
+
PLATFORMS
|
25
|
+
ruby
|
26
|
+
|
27
|
+
DEPENDENCIES
|
28
|
+
bundler (~> 1.0.0)
|
29
|
+
cinatra
|
30
|
+
jeweler (~> 1.5.2)
|
31
|
+
nokogiri
|
32
|
+
rcov
|
33
|
+
rr (~> 1.0.2)
|
34
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 jugyo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
ruri
|
2
|
+
====
|
3
|
+
|
4
|
+
Ruri is the るりま shell.
|
5
|
+
|
6
|
+
Install
|
7
|
+
----
|
8
|
+
|
9
|
+
gem install ruri
|
10
|
+
|
11
|
+
Usage
|
12
|
+
----
|
13
|
+
|
14
|
+
Launch:
|
15
|
+
|
16
|
+
$ ruri
|
17
|
+
|
18
|
+
Search:
|
19
|
+
|
20
|
+
> search gsub
|
21
|
+
|
22
|
+
You can open a individual reference by specify the index:
|
23
|
+
|
24
|
+
> open 0
|
25
|
+
|
26
|
+
You can go to the first in search result quickly:
|
27
|
+
|
28
|
+
> go 正規表現
|
29
|
+
|
30
|
+
TODO
|
31
|
+
----
|
32
|
+
|
33
|
+
* change prompt
|
34
|
+
* save the reference as history
|
35
|
+
|
36
|
+
Contributing to ruri
|
37
|
+
----
|
38
|
+
|
39
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
40
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
41
|
+
* Fork the project
|
42
|
+
* Start a feature/bugfix branch
|
43
|
+
* Commit and push until you are happy with your contribution
|
44
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
45
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
46
|
+
|
47
|
+
Copyright
|
48
|
+
----
|
49
|
+
|
50
|
+
Copyright (c) 2011 jugyo. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'jeweler'
|
14
|
+
Jeweler::Tasks.new do |gem|
|
15
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
|
+
gem.name = "ruri"
|
17
|
+
gem.homepage = "http://github.com/jugyo/ruri"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = %Q{the るりま shell}
|
20
|
+
gem.description = %Q{Ruri is the るりま shell.}
|
21
|
+
gem.email = "jugyo.org@gmail.com"
|
22
|
+
gem.authors = ["jugyo"]
|
23
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
24
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
25
|
+
gem.add_runtime_dependency 'cinatra'
|
26
|
+
gem.add_runtime_dependency 'nokogiri'
|
27
|
+
gem.add_development_dependency 'rspec', "~> 2.3.0"
|
28
|
+
gem.add_development_dependency 'rr', "~> 1.0.2"
|
29
|
+
end
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rspec/core'
|
33
|
+
require 'rspec/core/rake_task'
|
34
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
35
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
39
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
40
|
+
spec.rcov = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "ruri #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/ruri
ADDED
data/lib/ruri.rb
ADDED
data/lib/ruri/search.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'erb'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
module Ruri
|
7
|
+
class Search
|
8
|
+
Result = Struct.new(:title, :url, :summary)
|
9
|
+
|
10
|
+
BASE_URL = "http://doc.ruby-lang.org"
|
11
|
+
SEARCH_URL = "#{BASE_URL}/ja/search/version:%s/query:%s/"
|
12
|
+
DEFAULT_VERSION = '1.9.2'
|
13
|
+
|
14
|
+
class << self
|
15
|
+
attr_accessor :last_result, :last_query
|
16
|
+
|
17
|
+
def last_result
|
18
|
+
@last_result ||= []
|
19
|
+
end
|
20
|
+
|
21
|
+
def web_page_cache
|
22
|
+
@web_page_cache ||= {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def open(uri)
|
26
|
+
puts "\e[34m=> #{uri}\e[0m"
|
27
|
+
if web_page_cache.key?(uri)
|
28
|
+
web_page_cache[uri]
|
29
|
+
else
|
30
|
+
web_page_cache[uri] = Kernel.open(uri).read
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def search(query, options = {})
|
35
|
+
options = {:version => DEFAULT_VERSION, :memory => false}.merge(options)
|
36
|
+
url = SEARCH_URL % [options[:version], ERB::Util.url_encode(query)]
|
37
|
+
content = open(url)
|
38
|
+
result = parse_search_result(content)
|
39
|
+
if options[:memory]
|
40
|
+
self.last_query = query
|
41
|
+
self.last_result = result
|
42
|
+
end
|
43
|
+
result
|
44
|
+
end
|
45
|
+
|
46
|
+
def parse_search_result(html)
|
47
|
+
result = []
|
48
|
+
doc = Nokogiri::HTML(html)
|
49
|
+
doc.css('.entries').each do |dl|
|
50
|
+
[dl.css('.entry-name a'), dl.css('.entry-summary')].transpose.each do |link, summary|
|
51
|
+
result << Result.new(link.content.strip, BASE_URL + link[:href], summary.content.strip)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
result
|
55
|
+
end
|
56
|
+
|
57
|
+
def open_reference(result)
|
58
|
+
return nil unless result
|
59
|
+
parse_reference(open(result.url))
|
60
|
+
end
|
61
|
+
|
62
|
+
def parse_reference(html)
|
63
|
+
doc = Nokogiri::HTML(html)
|
64
|
+
doc.css('title').remove
|
65
|
+
first_p = doc.css('p').first
|
66
|
+
first_p.content = "\e[34m#{first_p.content.gsub("\n", " ").strip}\e[0m\n"
|
67
|
+
doc.css('h1').each {|e| e.content = "#{e.content.strip}\n#{'=' * 80}\n"}
|
68
|
+
doc.css('h2').each {|e| e.content = "#{e.content.strip}\n#{'-' * 80}\n"}
|
69
|
+
doc.css('h3').each {|e| e.content = "### #{e.content.strip}\n"}
|
70
|
+
doc.css('h4').each {|e| e.content = "#### #{e.content.strip}\n"}
|
71
|
+
doc.css('dt.method-heading').each {|e| e.content = "\e[36m#{e.content.strip}\e[0m\n"}
|
72
|
+
doc.css('dd').each {|e| e.content = "\n #{e.content.strip.gsub("\n", "\n ")}\n"}
|
73
|
+
doc.css('pre').each {|e| e.content = "\n#{e.content.strip}\n"}
|
74
|
+
doc.content.gsub(/\n[\n\s]*\n/, "\n\n").strip
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
command 'search', <<HELP do |query|
|
81
|
+
Search the Ruby reference manual
|
82
|
+
HELP
|
83
|
+
Ruri::Util.less do |file|
|
84
|
+
file << <<-HELP
|
85
|
+
\e[41m You can open a individual reference as following > open 0 \e[0m
|
86
|
+
|
87
|
+
HELP
|
88
|
+
Ruri::Search.search(query, :memory => true).each_with_index do |result, index|
|
89
|
+
file << <<-RESULT
|
90
|
+
#{index} \e[42m#{result.title}\e[0m
|
91
|
+
\e[34m#{result.url}\e[0m
|
92
|
+
#{result.summary.gsub("\n", "\n ")}
|
93
|
+
|
94
|
+
RESULT
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
command 'open', <<HELP do |index|
|
100
|
+
Open the specified reference
|
101
|
+
HELP
|
102
|
+
if ref = Ruri::Search.open_reference(Ruri::Search.last_result[index.to_i])
|
103
|
+
Ruri::Util.less(ref)
|
104
|
+
else
|
105
|
+
puts "\e[31mNot found :(\e[0m"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
command 'go', <<HELP do |query|
|
110
|
+
Go to the page
|
111
|
+
HELP
|
112
|
+
if ref = Ruri::Search.open_reference(Ruri::Search.search(query).first)
|
113
|
+
Ruri::Util.less(ref)
|
114
|
+
else
|
115
|
+
puts "\e[31mNot found :(\e[0m"
|
116
|
+
end
|
117
|
+
end
|
data/lib/ruri/util.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Ruri
|
2
|
+
module Util
|
3
|
+
PAGER = 'less -R -f'
|
4
|
+
class << self
|
5
|
+
def less(str = nil)
|
6
|
+
Tempfile.open('jugyo_is_very_cool') do |file|
|
7
|
+
yield file if block_given?
|
8
|
+
file << str if str
|
9
|
+
file.flush
|
10
|
+
system "#{PAGER} #{file.path}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
command 'eval', <<HELP do |arg|
|
18
|
+
Eval as ruby script
|
19
|
+
HELP
|
20
|
+
p eval(arg, binding, __FILE__, __LINE__) unless arg.empty?
|
21
|
+
end
|
22
|
+
|
23
|
+
command 'irb', <<HELP do |arg|
|
24
|
+
Start irb
|
25
|
+
HELP
|
26
|
+
require 'irb'
|
27
|
+
IRB.start
|
28
|
+
end
|
@@ -0,0 +1,1303 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
|
5
|
+
<head>
|
6
|
+
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
7
|
+
<title>バージョン:1.9.2 > クエリ:gsub | るりまサーチ</title>
|
8
|
+
<link rel="search"
|
9
|
+
type="application/opensearchdescription+xml"
|
10
|
+
title="るりまサーチ"
|
11
|
+
href="/ja/search/version:1.9.2/open_search_description.xml" />
|
12
|
+
<link rel="stylesheet" href="/ja/search/css/rurema.css"
|
13
|
+
type="text/css" media="all" />
|
14
|
+
<link rel="shortcut icon" href="/ja/search/favicon.ico" />
|
15
|
+
<script src="/ja/search/javascripts/jquery.min.js"
|
16
|
+
type="text/javascript"></script>
|
17
|
+
</head>
|
18
|
+
<body>
|
19
|
+
<div id="top" class="header">
|
20
|
+
<h1><a href="/ja/search/"><img src="/ja/search/images/rurema-search-title.png" alt="るりまサーチ" title="るりまサーチ" /></a></h1>
|
21
|
+
<div class="description">最速Rubyリファレンスマニュアル検索!</div>
|
22
|
+
<div class="search-form">
|
23
|
+
<form method="POST" action="./">
|
24
|
+
<input type="text" class="query" name="query" value="gsub" />
|
25
|
+
<input type="submit" value="検索" />
|
26
|
+
</form>
|
27
|
+
</div>
|
28
|
+
|
29
|
+
</div>
|
30
|
+
<div class="content">
|
31
|
+
<div class="search-header">
|
32
|
+
<div class="version-select">
|
33
|
+
<ul>
|
34
|
+
<li class="version-select">
|
35
|
+
<a class="version-select-link" href="/ja/search/query:gsub/">すべて</a>
|
36
|
+
</li>
|
37
|
+
|
38
|
+
<li class="version-select">
|
39
|
+
<a class="version-select-link" href="/ja/search/query:gsub/version:1.8.6/">1.8.6</a>
|
40
|
+
</li>
|
41
|
+
|
42
|
+
<li class="version-select">
|
43
|
+
<a class="version-select-link" href="/ja/search/query:gsub/version:1.8.7/">1.8.7</a>
|
44
|
+
</li>
|
45
|
+
|
46
|
+
<li class="version-select">
|
47
|
+
<a class="version-select-link" href="/ja/search/query:gsub/version:1.9.1/">1.9.1</a>
|
48
|
+
</li>
|
49
|
+
|
50
|
+
<li class="version-select-current">
|
51
|
+
<span class="version-select-text">1.9.2</span>
|
52
|
+
</li>
|
53
|
+
|
54
|
+
</ul>
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<div class="statistics">
|
58
|
+
<span class="total">26件ヒット</span>
|
59
|
+
|
60
|
+
<span class="showen-records">
|
61
|
+
[1-26件を表示]
|
62
|
+
</span>
|
63
|
+
|
64
|
+
<span class="elapsed-time">(0.013秒)</span>
|
65
|
+
</div>
|
66
|
+
|
67
|
+
<div class="topic-path">
|
68
|
+
<span class="topic-element"><span class="all-items"><a href="/ja/search/">トップページ</a></span></span> > <span class="topic-element"><img class="parameter-version" alt="バージョン" title="バージョン" src="/ja/search/images/version-icon.png" />:<a href="./../">1.9.2</a><a class="drop-condition" href="../../query:gsub/"><img alt="[x]" title="条件を削除" src="/ja/search/images/drop-condition-icon.png" /></a></span> > <span class="topic-element"><img class="parameter-query" alt="クエリ" title="クエリ" src="/ja/search/images/query-icon.png" />:gsub<a class="drop-condition" href="../"><img alt="[x]" title="条件を削除" src="/ja/search/images/drop-condition-icon.png" /></a></span>
|
69
|
+
</div>
|
70
|
+
</div>
|
71
|
+
|
72
|
+
<div class="search-result">
|
73
|
+
<div class="drilldowns">
|
74
|
+
<div class="drilldown list-box">
|
75
|
+
<h2 class="drilldown-type">種類</h2>
|
76
|
+
<ul class="drilldown-items">
|
77
|
+
|
78
|
+
<li class="drilldown-item-instance-method">
|
79
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
80
|
+
(19)
|
81
|
+
</li>
|
82
|
+
|
83
|
+
<li class="drilldown-item-document">
|
84
|
+
<a href="./type:document/">文書</a>
|
85
|
+
(5)
|
86
|
+
</li>
|
87
|
+
|
88
|
+
<li class="drilldown-item-library">
|
89
|
+
<a href="./type:library/">ライブラリ</a>
|
90
|
+
(1)
|
91
|
+
</li>
|
92
|
+
|
93
|
+
<li class="drilldown-item-singleton-method">
|
94
|
+
<a href="./type:singleton-method/">シングルトンメソッド</a>
|
95
|
+
(1)
|
96
|
+
</li>
|
97
|
+
|
98
|
+
</ul>
|
99
|
+
</div>
|
100
|
+
</div>
|
101
|
+
|
102
|
+
<div class="result">
|
103
|
+
<dl class="entries">
|
104
|
+
<dt class="entry-name">
|
105
|
+
<a href="/ja/1.9.2/method/String/i/gsub.html">String<wbr />#<wbr />gsub(pattern<wbr />,<wbr /> replace) -> String</a>
|
106
|
+
<span class="score">(1235)</span>
|
107
|
+
</dt>
|
108
|
+
<dd>
|
109
|
+
<div class="entry-summary">
|
110
|
+
<p>
|
111
|
+
文字列中で pattern にマッチする部分全てを
|
112
|
+
文字列 replace で置き換えた文字列を生成し返します。</p>
|
113
|
+
</div>
|
114
|
+
<div class="entry-description">
|
115
|
+
<span class="entry-version">
|
116
|
+
<a href="/ja/1.9.2/method/String/i/gsub.html">1.9.2</a>
|
117
|
+
</span>
|
118
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>e pattern で指定した文字列と置き換える文字列
|
119
|
+
|
120
|
+
例:
|
121
|
+
p 'abcdefg'.<span class="keyword">gsub</span>(/def/, '!!') # => "abc!!g"
|
122
|
+
p 'abcabc'.<span class="keyword">gsub</span>(/b/, '<<\&>>') # => "a<<b>>ca<<b>>c"
|
123
|
+
p 'xxbbxbb'.<span class="keyword">gsub</span>(/x+(b+)/, 'X<<\1>>') # => "X<<bb>>X<<bb>>"
|
124
|
+
|
125
|
+
注意:
|
126
|
+
|
127
|
+
第 2 引数 replace に $1 を<span class="separator">...</span></div><div class="snippet"><span class="separator">...</span>列が評価される時点ではまだ正規表現マッチが行われておらず、
|
128
|
+
$1 がセットされていないからです。
|
129
|
+
|
130
|
+
また、<span class="keyword">gsub</span> では「\」が部分文字列との置き換えという特別な意味を持つため、
|
131
|
+
replace に「\」自身を入れたいときは
|
132
|
+
「\」<span class="separator">...</span></div><div class="snippet"><span class="separator">...</span>
|
133
|
+
p 'xbbb-xbbb'.<span class="keyword">gsub</span>(/x(b+)/, "#{$1}") # => "-" # NG
|
134
|
+
p 'xbbb-xbbb'.<span class="keyword">gsub</span>(/x(b+)/, "\1") # => "1-1" # NG
|
135
|
+
p 'xbbb-xbbb'.<span class="keyword">gsub</span>(/x(b+)/, "\\1") # => "bbb-bbb" # OK
|
136
|
+
p 'xbbb-xbbb'.<span class="keyword">gsub</span>(/x(b+)/, '\1') # => "bbb-bbb" # OK
|
137
|
+
p 'xbbb-xbbb'.<span class="keyword">gsub</span>(/x(b+)/, '\\1') <span class="separator">...</span></div></div>
|
138
|
+
</div>
|
139
|
+
<ul class="entry-metadata">
|
140
|
+
<li class="entry-type">
|
141
|
+
<span class="entry-instance-method">
|
142
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
143
|
+
</span>
|
144
|
+
</li>
|
145
|
+
</ul>
|
146
|
+
<ul class="entry-related-entries">
|
147
|
+
<li class="entry-related-entry-query">
|
148
|
+
<a href="/version:1.9.2/query:Kernel%24%27/">Kernel$'</a>
|
149
|
+
</li>
|
150
|
+
<li class="entry-related-entry-query">
|
151
|
+
<a href="/version:1.9.2/query:Kernel%24%2B/">Kernel$+</a>
|
152
|
+
</li>
|
153
|
+
<li class="entry-related-entry-query">
|
154
|
+
<a href="/version:1.9.2/query:Kernel%241/">Kernel$1</a>
|
155
|
+
</li>
|
156
|
+
<li class="entry-related-entry-query">
|
157
|
+
<a href="/version:1.9.2/query:Kernel%24%60/">Kernel$`</a>
|
158
|
+
</li>
|
159
|
+
<li class="entry-related-entry-class">
|
160
|
+
<a href="./class:String/">String</a>
|
161
|
+
</li>
|
162
|
+
<li class="entry-related-entry-query">
|
163
|
+
<a href="/version:1.9.2/query:String%23sub/">String#sub</a>
|
164
|
+
</li>
|
165
|
+
</ul>
|
166
|
+
<dt class="entry-name">
|
167
|
+
<a href="/ja/1.9.2/method/Rake=3a=3aFileList/i/gsub.html">Rake<wbr />::<wbr />FileList<wbr />#<wbr />gsub(pattern<wbr />,<wbr /> replace) -> Rake<wbr />::<wbr />FileList</a>
|
168
|
+
<span class="score">(1099)</span>
|
169
|
+
</dt>
|
170
|
+
<dd>
|
171
|
+
<div class="entry-summary">
|
172
|
+
<p>
|
173
|
+
自身に含まれるファイルリストのそれぞれのエントリに対して String#gsub を実行し、
|
174
|
+
結果を新しい Rake::FileList として返します。</p>
|
175
|
+
</div>
|
176
|
+
<div class="entry-description">
|
177
|
+
<span class="entry-version">
|
178
|
+
<a href="/ja/1.9.2/method/Rake=3a=3aFileList/i/gsub.html">1.9.2</a>
|
179
|
+
</span>
|
180
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>に含まれるファイルリストのそれぞれのエントリに対して String#<span class="keyword">gsub</span> を実行し、
|
181
|
+
結果を新しい Rake::FileList として返します。
|
182
|
+
|
183
|
+
例:
|
184
|
+
FileList['lib/test/file', 'x/y'].<span class="keyword">gsub</span>(/\//, "\\") # => ['lib\\test\\file', 'x\\y']
|
185
|
+
|
186
|
+
<span class="separator">...</span></div></div>
|
187
|
+
</div>
|
188
|
+
<ul class="entry-metadata">
|
189
|
+
<li class="entry-type">
|
190
|
+
<span class="entry-instance-method">
|
191
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
192
|
+
</span>
|
193
|
+
</li>
|
194
|
+
</ul>
|
195
|
+
<ul class="entry-related-entries">
|
196
|
+
<li class="entry-related-entry-query">
|
197
|
+
<a href="/version:1.9.2/query:Rake%3A%3AFileList/">Rake::FileList</a>
|
198
|
+
</li>
|
199
|
+
<li class="entry-related-entry-query">
|
200
|
+
<a href="/version:1.9.2/query:String%23gsub/">String#gsub</a>
|
201
|
+
</li>
|
202
|
+
</ul>
|
203
|
+
<dt class="entry-name">
|
204
|
+
<a href="/ja/1.9.2/method/String/i/gsub.html">String<wbr />#<wbr />gsub(pattern) -> Enumerator</a>
|
205
|
+
<span class="score">(1095)</span>
|
206
|
+
</dt>
|
207
|
+
<dd>
|
208
|
+
<div class="entry-summary">
|
209
|
+
<p>
|
210
|
+
文字列中で pattern にマッチした部分を順番にブロックに渡し、
|
211
|
+
その実行結果で置き換えます。
|
212
|
+
ブロックなしの場合と違い、ブロックの中からは
|
213
|
+
組み込み変数 $1, $2, $3, ... を問題なく参照できます。</p>
|
214
|
+
</div>
|
215
|
+
<div class="entry-description">
|
216
|
+
<span class="entry-version">
|
217
|
+
<a href="/ja/1.9.2/method/String/i/gsub.html">1.9.2</a>
|
218
|
+
</span>
|
219
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>ターンになります。
|
220
|
+
|
221
|
+
@param pattern 置き換える文字列のパターン
|
222
|
+
@return 置換した場合は self、置換しなかった場合は nil
|
223
|
+
|
224
|
+
例:
|
225
|
+
|
226
|
+
p 'abcabc'.<span class="keyword">gsub</span>(/[bc]/) {|s| s.upcase } #=> "aBCaBC"
|
227
|
+
p 'abcabc'.<span class="keyword">gsub</span>(/[bc]/) { $&.upcase } #=> "aBCaBC"
|
228
|
+
|
229
|
+
@see String#sub
|
230
|
+
|
231
|
+
<span class="separator">...</span></div></div>
|
232
|
+
</div>
|
233
|
+
<ul class="entry-metadata">
|
234
|
+
<li class="entry-type">
|
235
|
+
<span class="entry-instance-method">
|
236
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
237
|
+
</span>
|
238
|
+
</li>
|
239
|
+
</ul>
|
240
|
+
<ul class="entry-related-entries">
|
241
|
+
<li class="entry-related-entry-query">
|
242
|
+
<a href="/version:1.9.2/query:Kernel%241/">Kernel$1</a>
|
243
|
+
</li>
|
244
|
+
<li class="entry-related-entry-class">
|
245
|
+
<a href="./class:String/">String</a>
|
246
|
+
</li>
|
247
|
+
<li class="entry-related-entry-query">
|
248
|
+
<a href="/version:1.9.2/query:String%23sub/">String#sub</a>
|
249
|
+
</li>
|
250
|
+
</ul>
|
251
|
+
<dt class="entry-name">
|
252
|
+
<a href="/ja/1.9.2/method/String/i/gsub.html">String<wbr />#<wbr />gsub(pattern) {|matched| <wbr />.<wbr /><wbr />.<wbr /><wbr />.<wbr /><wbr />.<wbr /> } -> String</a>
|
253
|
+
<span class="score">(1095)</span>
|
254
|
+
</dt>
|
255
|
+
<dd>
|
256
|
+
<div class="entry-summary">
|
257
|
+
<p>
|
258
|
+
文字列中で pattern にマッチした部分を順番にブロックに渡し、
|
259
|
+
その実行結果で置き換えます。
|
260
|
+
ブロックなしの場合と違い、ブロックの中からは
|
261
|
+
組み込み変数 $1, $2, $3, ... を問題なく参照できます。</p>
|
262
|
+
</div>
|
263
|
+
<div class="entry-description">
|
264
|
+
<span class="entry-version">
|
265
|
+
<a href="/ja/1.9.2/method/String/i/gsub.html">1.9.2</a>
|
266
|
+
</span>
|
267
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>ターンになります。
|
268
|
+
|
269
|
+
@param pattern 置き換える文字列のパターン
|
270
|
+
@return 置換した場合は self、置換しなかった場合は nil
|
271
|
+
|
272
|
+
例:
|
273
|
+
|
274
|
+
p 'abcabc'.<span class="keyword">gsub</span>(/[bc]/) {|s| s.upcase } #=> "aBCaBC"
|
275
|
+
p 'abcabc'.<span class="keyword">gsub</span>(/[bc]/) { $&.upcase } #=> "aBCaBC"
|
276
|
+
|
277
|
+
@see String#sub
|
278
|
+
|
279
|
+
<span class="separator">...</span></div></div>
|
280
|
+
</div>
|
281
|
+
<ul class="entry-metadata">
|
282
|
+
<li class="entry-type">
|
283
|
+
<span class="entry-instance-method">
|
284
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
285
|
+
</span>
|
286
|
+
</li>
|
287
|
+
</ul>
|
288
|
+
<ul class="entry-related-entries">
|
289
|
+
<li class="entry-related-entry-query">
|
290
|
+
<a href="/version:1.9.2/query:Kernel%241/">Kernel$1</a>
|
291
|
+
</li>
|
292
|
+
<li class="entry-related-entry-class">
|
293
|
+
<a href="./class:String/">String</a>
|
294
|
+
</li>
|
295
|
+
<li class="entry-related-entry-query">
|
296
|
+
<a href="/version:1.9.2/query:String%23sub/">String#sub</a>
|
297
|
+
</li>
|
298
|
+
</ul>
|
299
|
+
<dt class="entry-name">
|
300
|
+
<a href="/ja/1.9.2/method/String/i/gsub.html">String<wbr />#<wbr />gsub(pattern<wbr />,<wbr /> hash) -> String</a>
|
301
|
+
<span class="score">(1095)</span>
|
302
|
+
</dt>
|
303
|
+
<dd>
|
304
|
+
<div class="entry-summary">
|
305
|
+
<p>
|
306
|
+
文字列中の pattern にマッチした部分をキーにして hash を引いた値で置き換えます。</p>
|
307
|
+
</div>
|
308
|
+
<div class="entry-description">
|
309
|
+
<span class="entry-version">
|
310
|
+
<a href="/ja/1.9.2/method/String/i/gsub.html">1.9.2</a>
|
311
|
+
</span>
|
312
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>ash を引いた値で置き換えます。
|
313
|
+
|
314
|
+
@param pattern 置き換える文字列のパターン
|
315
|
+
@param hash 置き換える文字列を与えるハッシュ
|
316
|
+
|
317
|
+
hash = {'b'=>'B', 'c'=>'C'}
|
318
|
+
p "abcabc".<span class="keyword">gsub</span>(/[bc]/){hash[$&]} #=> "aBCaBC"
|
319
|
+
p "abcabc".<span class="keyword">gsub</span>(/[bc]/, hash) #=> "aBCaBC"
|
320
|
+
|
321
|
+
<span class="separator">...</span></div></div>
|
322
|
+
</div>
|
323
|
+
<ul class="entry-metadata">
|
324
|
+
<li class="entry-type">
|
325
|
+
<span class="entry-instance-method">
|
326
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
327
|
+
</span>
|
328
|
+
</li>
|
329
|
+
</ul>
|
330
|
+
<ul class="entry-related-entries">
|
331
|
+
<li class="entry-related-entry-class">
|
332
|
+
<a href="./class:String/">String</a>
|
333
|
+
</li>
|
334
|
+
</ul>
|
335
|
+
<p class="jump-to-top"><a href="#top">絞り込み条件を変える</a></p>
|
336
|
+
<dt class="entry-name">
|
337
|
+
<a href="/ja/1.9.2/method/String/i/gsub=21.html">String<wbr />#<wbr />gsub!(pattern<wbr />,<wbr /> replace) -> self | nil</a>
|
338
|
+
<span class="score">(191)</span>
|
339
|
+
</dt>
|
340
|
+
<dd>
|
341
|
+
<div class="entry-summary">
|
342
|
+
<p>
|
343
|
+
文字列中で pattern にマッチする部分全てを文字列 replace に破壊的に置き換えます。</p>
|
344
|
+
</div>
|
345
|
+
<div class="entry-description">
|
346
|
+
<span class="entry-version">
|
347
|
+
<a href="/ja/1.9.2/method/String/i/gsub=21.html">1.9.2</a>
|
348
|
+
</span>
|
349
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>弧の内容に置き換えられます。
|
350
|
+
置換文字列内では \`、\'、\+ も使えます。
|
351
|
+
これらは $`、$'、$+ に対応します。<span class="keyword">
|
352
|
+
|
353
|
+
gsub</span>! は通常 self を変更して返しますが、
|
354
|
+
置換が起こらなかった場合は nil を返します。
|
355
|
+
|
356
|
+
@param pattern 置き換え<span class="separator">...</span></div><div class="snippet"><span class="separator">...</span>buf = "String-String"
|
357
|
+
buf.<span class="keyword">gsub</span>!(/in./, "!!")
|
358
|
+
p buf # => "Str!!-Str!!"
|
359
|
+
|
360
|
+
buf = "String.String"
|
361
|
+
buf.<span class="keyword">gsub</span>!(/in./, '<<\&>>')
|
362
|
+
p buf # => "Str<<ing>>-Str<<ing>>"
|
363
|
+
|
364
|
+
注意:
|
365
|
+
|
366
|
+
引数 replace の中で $1 を使うことはできません。
|
367
|
+
replace は<span class="keyword"> gsub</span> メソッドの呼び出し<span class="separator">...</span></div><div class="snippet"><span class="separator">...</span>より先に評価されるので、
|
368
|
+
まだ<span class="keyword"> gsub</span> の正規表現マッチが行われておらず、
|
369
|
+
$1 がセットされていないからです。
|
370
|
+
|
371
|
+
また、<span class="keyword">gsub</span> では「\」が部分文字列との置き換えという特別な意味を持つため、
|
372
|
+
replace に「\」自身を入れたいと<span class="separator">...</span></div></div>
|
373
|
+
</div>
|
374
|
+
<ul class="entry-metadata">
|
375
|
+
<li class="entry-type">
|
376
|
+
<span class="entry-instance-method">
|
377
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
378
|
+
</span>
|
379
|
+
</li>
|
380
|
+
</ul>
|
381
|
+
<ul class="entry-related-entries">
|
382
|
+
<li class="entry-related-entry-query">
|
383
|
+
<a href="/version:1.9.2/query:Kernel%24%27/">Kernel$'</a>
|
384
|
+
</li>
|
385
|
+
<li class="entry-related-entry-query">
|
386
|
+
<a href="/version:1.9.2/query:Kernel%24%2B/">Kernel$+</a>
|
387
|
+
</li>
|
388
|
+
<li class="entry-related-entry-query">
|
389
|
+
<a href="/version:1.9.2/query:Kernel%241/">Kernel$1</a>
|
390
|
+
</li>
|
391
|
+
<li class="entry-related-entry-query">
|
392
|
+
<a href="/version:1.9.2/query:Kernel%24%60/">Kernel$`</a>
|
393
|
+
</li>
|
394
|
+
<li class="entry-related-entry-class">
|
395
|
+
<a href="./class:String/">String</a>
|
396
|
+
</li>
|
397
|
+
<li class="entry-related-entry-query">
|
398
|
+
<a href="/version:1.9.2/query:String%23sub/">String#sub</a>
|
399
|
+
</li>
|
400
|
+
</ul>
|
401
|
+
<dt class="entry-name">
|
402
|
+
<a href="/ja/1.9.2/method/String/i/gsub=21.html">String<wbr />#<wbr />gsub!(pattern) -> Enumerator</a>
|
403
|
+
<span class="score">(91)</span>
|
404
|
+
</dt>
|
405
|
+
<dd>
|
406
|
+
<div class="entry-summary">
|
407
|
+
<p>
|
408
|
+
文字列中で pattern にマッチする部分全てを順番にブロックに渡し、
|
409
|
+
その評価結果に置き換えます。</p>
|
410
|
+
</div>
|
411
|
+
<div class="entry-description">
|
412
|
+
<span class="entry-version">
|
413
|
+
<a href="/ja/1.9.2/method/String/i/gsub=21.html">1.9.2</a>
|
414
|
+
</span>
|
415
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>n 置き換える文字列のパターン
|
416
|
+
@return 置換した場合は self、置換しなかった場合は nil
|
417
|
+
|
418
|
+
例:
|
419
|
+
str = 'abcabc'
|
420
|
+
str.<span class="keyword">gsub</span>!(/b/) {|s| s.upcase }
|
421
|
+
p str #=> "aBcaBc"
|
422
|
+
|
423
|
+
str = 'abcabc'
|
424
|
+
str.<span class="keyword">gsub</span>!(/b/) { $&.upcase }
|
425
|
+
p str #=> "aBcaBc"
|
426
|
+
|
427
|
+
@see String#sub
|
428
|
+
|
429
|
+
<span class="separator">...</span></div></div>
|
430
|
+
</div>
|
431
|
+
<ul class="entry-metadata">
|
432
|
+
<li class="entry-type">
|
433
|
+
<span class="entry-instance-method">
|
434
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
435
|
+
</span>
|
436
|
+
</li>
|
437
|
+
</ul>
|
438
|
+
<ul class="entry-related-entries">
|
439
|
+
<li class="entry-related-entry-query">
|
440
|
+
<a href="/version:1.9.2/query:Kernel%241/">Kernel$1</a>
|
441
|
+
</li>
|
442
|
+
<li class="entry-related-entry-class">
|
443
|
+
<a href="./class:String/">String</a>
|
444
|
+
</li>
|
445
|
+
<li class="entry-related-entry-query">
|
446
|
+
<a href="/version:1.9.2/query:String%23sub/">String#sub</a>
|
447
|
+
</li>
|
448
|
+
</ul>
|
449
|
+
<dt class="entry-name">
|
450
|
+
<a href="/ja/1.9.2/method/String/i/gsub=21.html">String<wbr />#<wbr />gsub!(pattern) {|matched| <wbr />.<wbr /><wbr />.<wbr /><wbr />.<wbr /><wbr />.<wbr /> } -> self | nil</a>
|
451
|
+
<span class="score">(91)</span>
|
452
|
+
</dt>
|
453
|
+
<dd>
|
454
|
+
<div class="entry-summary">
|
455
|
+
<p>
|
456
|
+
文字列中で pattern にマッチする部分全てを順番にブロックに渡し、
|
457
|
+
その評価結果に置き換えます。</p>
|
458
|
+
</div>
|
459
|
+
<div class="entry-description">
|
460
|
+
<span class="entry-version">
|
461
|
+
<a href="/ja/1.9.2/method/String/i/gsub=21.html">1.9.2</a>
|
462
|
+
</span>
|
463
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>n 置き換える文字列のパターン
|
464
|
+
@return 置換した場合は self、置換しなかった場合は nil
|
465
|
+
|
466
|
+
例:
|
467
|
+
str = 'abcabc'
|
468
|
+
str.<span class="keyword">gsub</span>!(/b/) {|s| s.upcase }
|
469
|
+
p str #=> "aBcaBc"
|
470
|
+
|
471
|
+
str = 'abcabc'
|
472
|
+
str.<span class="keyword">gsub</span>!(/b/) { $&.upcase }
|
473
|
+
p str #=> "aBcaBc"
|
474
|
+
|
475
|
+
@see String#sub
|
476
|
+
|
477
|
+
<span class="separator">...</span></div></div>
|
478
|
+
</div>
|
479
|
+
<ul class="entry-metadata">
|
480
|
+
<li class="entry-type">
|
481
|
+
<span class="entry-instance-method">
|
482
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
483
|
+
</span>
|
484
|
+
</li>
|
485
|
+
</ul>
|
486
|
+
<ul class="entry-related-entries">
|
487
|
+
<li class="entry-related-entry-query">
|
488
|
+
<a href="/version:1.9.2/query:Kernel%241/">Kernel$1</a>
|
489
|
+
</li>
|
490
|
+
<li class="entry-related-entry-class">
|
491
|
+
<a href="./class:String/">String</a>
|
492
|
+
</li>
|
493
|
+
<li class="entry-related-entry-query">
|
494
|
+
<a href="/version:1.9.2/query:String%23sub/">String#sub</a>
|
495
|
+
</li>
|
496
|
+
</ul>
|
497
|
+
<dt class="entry-name">
|
498
|
+
<a href="/ja/1.9.2/method/String/i/gsub=21.html">String<wbr />#<wbr />gsub!(pattern<wbr />,<wbr /> hash) -> self | nil</a>
|
499
|
+
<span class="score">(91)</span>
|
500
|
+
</dt>
|
501
|
+
<dd>
|
502
|
+
<div class="entry-summary">
|
503
|
+
<p>
|
504
|
+
文字列中の pattern にマッチした部分をキーにして hash を引いた値で置き換えます。</p>
|
505
|
+
</div>
|
506
|
+
<div class="entry-description">
|
507
|
+
<span class="entry-version">
|
508
|
+
<a href="/ja/1.9.2/method/String/i/gsub=21.html">1.9.2</a>
|
509
|
+
</span>
|
510
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>ash を引いた値で置き換えます。
|
511
|
+
|
512
|
+
@param pattern 置き換える文字列のパターン
|
513
|
+
@param hash 置き換える文字列を与えるハッシュ
|
514
|
+
|
515
|
+
hash = {'b'=>'B', 'c'=>'C'}
|
516
|
+
p "abcabc".<span class="keyword">gsub</span>(/[bc]/){hash[$&]} #=> "aBCaBC"
|
517
|
+
p "abcabc".<span class="keyword">gsub</span>(/[bc]/, hash) #=> "aBCaBC"
|
518
|
+
|
519
|
+
<span class="separator">...</span></div></div>
|
520
|
+
</div>
|
521
|
+
<ul class="entry-metadata">
|
522
|
+
<li class="entry-type">
|
523
|
+
<span class="entry-instance-method">
|
524
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
525
|
+
</span>
|
526
|
+
</li>
|
527
|
+
</ul>
|
528
|
+
<ul class="entry-related-entries">
|
529
|
+
<li class="entry-related-entry-class">
|
530
|
+
<a href="./class:String/">String</a>
|
531
|
+
</li>
|
532
|
+
</ul>
|
533
|
+
<dt class="entry-name">
|
534
|
+
<a href="/ja/1.9.2/doc/spec=2fregexp.html">正規表現</a>
|
535
|
+
<span class="score">(89)</span>
|
536
|
+
</dt>
|
537
|
+
<dd>
|
538
|
+
<div class="entry-summary">
|
539
|
+
<p>正規表現
|
540
|
+
正規表現に関してはd:spec/literal#regexp、$&、
|
541
|
+
Regexp そして MatchData なども参照して下さい。</p>
|
542
|
+
</div>
|
543
|
+
<div class="entry-description">
|
544
|
+
<span class="entry-version">
|
545
|
+
<a href="/ja/1.9.2/doc/spec=2fregexp.html">1.9.2</a>
|
546
|
+
</span>
|
547
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>マッチしていましたが、
|
548
|
+
常に文字列の末尾にもマッチするように変更されました。Regexp
|
549
|
+
//emlist{
|
550
|
+
p "\n".<span class="keyword">gsub</span>(/$/, "o")
|
551
|
+
=> "o\n" (1.6)
|
552
|
+
=> "o\no" (1.8) # 改行文字の前と文字列末尾の前で1回ずつ
|
553
|
+
//}
|
554
|
+
|
555
|
+
: .
|
556
|
+
|
557
|
+
改行を除く任意<span class="separator">...</span></div><div class="snippet"><span class="separator">...</span>マッチしていましたが、常に文字列の末尾にもマッチするように変更され
|
558
|
+
ました。Regexp
|
559
|
+
//emlist{
|
560
|
+
p "\n".<span class="keyword">gsub</span>(/\Z/, "o")
|
561
|
+
=> "o\n" (1.6)
|
562
|
+
=> "o\no" (1.8) # 改行文字の前と文字列末尾の前で1回ずつ
|
563
|
+
//}
|
564
|
+
|
565
|
+
: \z
|
566
|
+
|
567
|
+
文字列末尾<span class="separator">...</span></div><div class="snippet"><span class="separator">...</span>所(の直後)にマッチ (幅を持たない)。
|
568
|
+
初回だけは先頭位置にマッチします(\Aと同じ)。
|
569
|
+
|
570
|
+
String#scan や、String#<span class="keyword">gsub</span> で使用できます。前回マッチし
|
571
|
+
た場所の後からマッチさせたい場合に使用します。
|
572
|
+
|
573
|
+
簡単な(あまり役に立た<span class="separator">...</span></div></div>
|
574
|
+
</div>
|
575
|
+
<ul class="entry-metadata">
|
576
|
+
<li class="entry-type">
|
577
|
+
<span class="entry-document">
|
578
|
+
<a href="./type:document/">文書</a>
|
579
|
+
</span>
|
580
|
+
</li>
|
581
|
+
</ul>
|
582
|
+
<ul class="entry-related-entries">
|
583
|
+
<li class="entry-related-entry-query">
|
584
|
+
<a href="/version:1.9.2/query:Kernel%24%26/">Kernel$&</a>
|
585
|
+
</li>
|
586
|
+
<li class="entry-related-entry-query">
|
587
|
+
<a href="/version:1.9.2/query:Kernel%241/">Kernel$1</a>
|
588
|
+
</li>
|
589
|
+
<li class="entry-related-entry-query">
|
590
|
+
<a href="/version:1.9.2/query:Kernel%242/">Kernel$2</a>
|
591
|
+
</li>
|
592
|
+
<li class="entry-related-entry-query">
|
593
|
+
<a href="/version:1.9.2/query:MatchData/">MatchData</a>
|
594
|
+
</li>
|
595
|
+
<li class="entry-related-entry-query">
|
596
|
+
<a href="/version:1.9.2/query:Regexp/">Regexp</a>
|
597
|
+
</li>
|
598
|
+
<li class="entry-related-entry-query">
|
599
|
+
<a href="/version:1.9.2/query:String%23gsub/">String#gsub</a>
|
600
|
+
</li>
|
601
|
+
<li class="entry-related-entry-query">
|
602
|
+
<a href="/version:1.9.2/query:String%23scan/">String#scan</a>
|
603
|
+
</li>
|
604
|
+
</ul>
|
605
|
+
<p class="jump-to-top"><a href="#top">絞り込み条件を変える</a></p>
|
606
|
+
<dt class="entry-name">
|
607
|
+
<a href="/ja/1.9.2/method/Rake=3a=3aFileList/i/gsub=21.html">Rake<wbr />::<wbr />FileList<wbr />#<wbr />gsub!(pattern<wbr />,<wbr /> replace) -> self</a>
|
608
|
+
<span class="score">(88)</span>
|
609
|
+
</dt>
|
610
|
+
<dd>
|
611
|
+
<div class="entry-summary">
|
612
|
+
<p>
|
613
|
+
自身に含まれるファイルリストのそれぞれのエントリに対して String#gsub を実行します。
|
614
|
+
自身を破壊的に変更します。</p>
|
615
|
+
</div>
|
616
|
+
<div class="entry-description">
|
617
|
+
<span class="entry-version">
|
618
|
+
<a href="/ja/1.9.2/method/Rake=3a=3aFileList/i/gsub=21.html">1.9.2</a>
|
619
|
+
</span>
|
620
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>
|
621
|
+
自身に含まれるファイルリストのそれぞれのエントリに対して String#<span class="keyword">gsub</span> を実行します。
|
622
|
+
自身を破壊的に変更します。
|
623
|
+
|
624
|
+
<span class="separator">...</span></div></div>
|
625
|
+
</div>
|
626
|
+
<ul class="entry-metadata">
|
627
|
+
<li class="entry-type">
|
628
|
+
<span class="entry-instance-method">
|
629
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
630
|
+
</span>
|
631
|
+
</li>
|
632
|
+
</ul>
|
633
|
+
<ul class="entry-related-entries">
|
634
|
+
<li class="entry-related-entry-class">
|
635
|
+
<a href="./class:Rake%3A%3AFileList/">Rake::FileList</a>
|
636
|
+
</li>
|
637
|
+
<li class="entry-related-entry-query">
|
638
|
+
<a href="/version:1.9.2/query:String%23gsub/">String#gsub</a>
|
639
|
+
</li>
|
640
|
+
</ul>
|
641
|
+
<dt class="entry-name">
|
642
|
+
<a href="/ja/1.9.2/doc/news=2f1=2e8=2e0.html">1<wbr />.<wbr />6<wbr />.<wbr />8から1<wbr />.<wbr />8<wbr />.<wbr />0への変更点(まとめ)</a>
|
643
|
+
<span class="score">(45)</span>
|
644
|
+
</dt>
|
645
|
+
<dd>
|
646
|
+
<div class="entry-summary">
|
647
|
+
<p>1.6.8から1.8.0への変更点(まとめ)
|
648
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/インタプリタの変更>))
|
649
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/追加されたクラス/モジュール>))
|
650
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/追加されたメソッド>))
|
651
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/追加された定数>))
|
652
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/拡張されたクラス/メソッド(互換性のある変更)>))
|
653
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/変更されたクラス/メソッド(互換性のない変更)>))
|
654
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/文法の変更>))
|
655
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/正規表現>))
|
656
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/Marshal>))
|
657
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/Windows 対応>))
|
658
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/廃止された(される予定の)機能>))
|
659
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/ライブラリ>))
|
660
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/拡張ライブラリAPI>))
|
661
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/バグ修正>))
|
662
|
+
* ((<1.6.8から1.8.0への変更点(まとめ)/サポートプラットフォームの追加>))</p>
|
663
|
+
</div>
|
664
|
+
<div class="entry-description">
|
665
|
+
<span class="entry-version">
|
666
|
+
<a href="/ja/1.9.2/doc/news=2f1=2e8=2e0.html">1.9.2</a>
|
667
|
+
</span>
|
668
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>
|
669
|
+
: ((<String#split|String/split>)) [change]
|
670
|
+
: ((<String#sub|String/sub>)), ((<String#sub!|String/sub!>)) [change]
|
671
|
+
: ((<String#<span class="keyword">gsub</span>|String/<span class="keyword">gsub</span>>)), ((<String#<span class="keyword">gsub</span>!|String/<span class="keyword">gsub</span>!>)) [change]
|
672
|
+
: ((<String#~|String/~>)) [obsolete]
|
673
|
+
: ((<String#=~|String/=~>)) [obsolete]
|
674
|
+
: ((<組み込み変数/$;>)) [com<span class="separator">...</span></div></div>
|
675
|
+
</div>
|
676
|
+
<ul class="entry-metadata">
|
677
|
+
<li class="entry-type">
|
678
|
+
<span class="entry-document">
|
679
|
+
<a href="./type:document/">文書</a>
|
680
|
+
</span>
|
681
|
+
</li>
|
682
|
+
</ul>
|
683
|
+
<ul class="entry-related-entries">
|
684
|
+
</ul>
|
685
|
+
<dt class="entry-name">
|
686
|
+
<a href="/ja/1.9.2/method/WEBrick=3a=3aHTTPProxyServer/s/new.html">WEBrick<wbr />::<wbr />HTTPProxyServer<wbr />.<wbr />new(config<wbr />,<wbr /> default = WEBrick<wbr />::<wbr />Config<wbr />::<wbr />HTTP) -> WEBrick<wbr />::<wbr />HTTPProxyServer</a>
|
687
|
+
<span class="score">(23)</span>
|
688
|
+
</dt>
|
689
|
+
<dd>
|
690
|
+
<div class="entry-summary">
|
691
|
+
<p>
|
692
|
+
プロクシオブジェクトを生成して返します。</p>
|
693
|
+
</div>
|
694
|
+
<div class="entry-description">
|
695
|
+
<span class="entry-version">
|
696
|
+
<a href="/ja/1.9.2/method/WEBrick=3a=3aHTTPProxyServer/s/new.html">1.9.2</a>
|
697
|
+
</span>
|
698
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>定した場合なにもしません。デフォルトは nil です。
|
699
|
+
//emlist{
|
700
|
+
handler = proc{|req, res|
|
701
|
+
res.body.<span class="keyword">gsub</span>!(/です。/e, 'でんがな。')
|
702
|
+
res.body.<span class="keyword">gsub</span>!(/ます。/e, 'まんがな。')
|
703
|
+
}
|
704
|
+
s = WEBrick::HTTPProxyServer.new( { :ProxyContentHandler => handler } )
|
705
|
+
//}
|
706
|
+
: :ProxyV<span class="separator">...</span></div></div>
|
707
|
+
</div>
|
708
|
+
<ul class="entry-metadata">
|
709
|
+
<li class="entry-type">
|
710
|
+
<span class="entry-singleton-method">
|
711
|
+
<a href="./type:singleton-method/">シングルトンメソッド</a>
|
712
|
+
</span>
|
713
|
+
</li>
|
714
|
+
</ul>
|
715
|
+
<ul class="entry-related-entries">
|
716
|
+
<li class="entry-related-entry-query">
|
717
|
+
<a href="/version:1.9.2/query:Proc/">Proc</a>
|
718
|
+
</li>
|
719
|
+
<li class="entry-related-entry-query">
|
720
|
+
<a href="/version:1.9.2/query:URI/">URI</a>
|
721
|
+
</li>
|
722
|
+
<li class="entry-related-entry-query">
|
723
|
+
<a href="/version:1.9.2/query:WEBrick%3A%3AConfig%3A%3AHTTP/">WEBrick::Config::HTTP</a>
|
724
|
+
</li>
|
725
|
+
<li class="entry-related-entry-query">
|
726
|
+
<a href="/version:1.9.2/query:WEBrick%3A%3AHTTPAuth%3A%3AProxyBasicAuth/">WEBrick::HTTPAuth::ProxyBasicAuth</a>
|
727
|
+
</li>
|
728
|
+
<li class="entry-related-entry-query">
|
729
|
+
<a href="/version:1.9.2/query:WEBrick%3A%3AHTTPAuth%3A%3AProxyDigestAuth/">WEBrick::HTTPAuth::ProxyDigestAuth</a>
|
730
|
+
</li>
|
731
|
+
<li class="entry-related-entry-class">
|
732
|
+
<a href="./class:WEBrick%3A%3AHTTPProxyServer/">WEBrick::HTTPProxyServer</a>
|
733
|
+
</li>
|
734
|
+
<li class="entry-related-entry-query">
|
735
|
+
<a href="/version:1.9.2/query:WEBrick%3A%3AHTTPRequest/">WEBrick::HTTPRequest</a>
|
736
|
+
</li>
|
737
|
+
<li class="entry-related-entry-query">
|
738
|
+
<a href="/version:1.9.2/query:WEBrick%3A%3AHTTPResponse/">WEBrick::HTTPResponse</a>
|
739
|
+
</li>
|
740
|
+
</ul>
|
741
|
+
<dt class="entry-name">
|
742
|
+
<a href="/ja/1.9.2/doc/news=2f1=2e9=2e0.html">ruby 1<wbr />.<wbr />9 feature</a>
|
743
|
+
<span class="score">(23)</span>
|
744
|
+
</dt>
|
745
|
+
<dd>
|
746
|
+
<div class="entry-summary">
|
747
|
+
<p>ruby 1.9 feature
|
748
|
+
ruby version 1.9.0 は開発版です。
|
749
|
+
以下にあげる機能は将来削除されたり互換性のない仕様変更がなされるかもしれません。
|
750
|
+
1.9.1 以降は安定版です。
|
751
|
+
バグ修正がメインになります。</p>
|
752
|
+
</div>
|
753
|
+
<div class="entry-description">
|
754
|
+
<span class="entry-version">
|
755
|
+
<a href="/ja/1.9.2/doc/news=2f1=2e9=2e0.html">1.9.2</a>
|
756
|
+
</span>
|
757
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>e とすると、GC を行えるすべての機会で GC を行います。
|
758
|
+
|
759
|
+
=== 2005-12-15
|
760
|
+
|
761
|
+
: sub [obsolete]
|
762
|
+
:<span class="keyword"> gsub</span> [obsolete]
|
763
|
+
: sub! [obsolete]
|
764
|
+
:<span class="keyword"> gsub</span>! [obsolete]
|
765
|
+
: chop [obsolete]
|
766
|
+
: chop! [obsolete]
|
767
|
+
: chomp [obsolete]
|
768
|
+
: chomp! [o<span class="separator">...</span></div></div>
|
769
|
+
</div>
|
770
|
+
<ul class="entry-metadata">
|
771
|
+
<li class="entry-type">
|
772
|
+
<span class="entry-document">
|
773
|
+
<a href="./type:document/">文書</a>
|
774
|
+
</span>
|
775
|
+
</li>
|
776
|
+
</ul>
|
777
|
+
<ul class="entry-related-entries">
|
778
|
+
</ul>
|
779
|
+
<dt class="entry-name">
|
780
|
+
<a href="/ja/1.9.2/method/String/i/sub=21.html">String<wbr />#<wbr />sub!(pattern) {|matched| <wbr />.<wbr /><wbr />.<wbr /><wbr />.<wbr /><wbr />.<wbr /> } -> self | nil</a>
|
781
|
+
<span class="score">(13)</span>
|
782
|
+
</dt>
|
783
|
+
<dd>
|
784
|
+
<div class="entry-summary">
|
785
|
+
<p>
|
786
|
+
文字列中で pattern にマッチした最初の部分をブロックに渡し、
|
787
|
+
その評価結果へ破壊的に置き換えます。</p>
|
788
|
+
</div>
|
789
|
+
<div class="entry-description">
|
790
|
+
<span class="entry-version">
|
791
|
+
<a href="/ja/1.9.2/method/String/i/sub=21.html">1.9.2</a>
|
792
|
+
</span>
|
793
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>rn 置き換える文字列のパターン
|
794
|
+
@return 置換した場合は self、置換しなかった場合は nil
|
795
|
+
|
796
|
+
例:
|
797
|
+
str = 'abcabc'
|
798
|
+
str.sub!(/b/) {|s| s.upcase }
|
799
|
+
p str #=> "aBcabc"
|
800
|
+
|
801
|
+
str = 'abcabc'
|
802
|
+
str.sub!(/b/) { $&.upcase }
|
803
|
+
p str #=> "aBcabc"
|
804
|
+
|
805
|
+
@see String#<span class="keyword">gsub</span>
|
806
|
+
|
807
|
+
<span class="separator">...</span></div></div>
|
808
|
+
</div>
|
809
|
+
<ul class="entry-metadata">
|
810
|
+
<li class="entry-type">
|
811
|
+
<span class="entry-instance-method">
|
812
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
813
|
+
</span>
|
814
|
+
</li>
|
815
|
+
</ul>
|
816
|
+
<ul class="entry-related-entries">
|
817
|
+
<li class="entry-related-entry-query">
|
818
|
+
<a href="/version:1.9.2/query:Kernel%241/">Kernel$1</a>
|
819
|
+
</li>
|
820
|
+
<li class="entry-related-entry-class">
|
821
|
+
<a href="./class:String/">String</a>
|
822
|
+
</li>
|
823
|
+
<li class="entry-related-entry-query">
|
824
|
+
<a href="/version:1.9.2/query:String%23gsub/">String#gsub</a>
|
825
|
+
</li>
|
826
|
+
</ul>
|
827
|
+
<p class="jump-to-top"><a href="#top">絞り込み条件を変える</a></p>
|
828
|
+
<dt class="entry-name">
|
829
|
+
<a href="/ja/1.9.2/method/String/i/sub=21.html">String<wbr />#<wbr />sub!(pattern<wbr />,<wbr /> replace) -> self | nil</a>
|
830
|
+
<span class="score">(13)</span>
|
831
|
+
</dt>
|
832
|
+
<dd>
|
833
|
+
<div class="entry-summary">
|
834
|
+
<p>
|
835
|
+
文字列中で pattern にマッチした最初の部分を文字列 replace へ破壊的に置き換えます。</p>
|
836
|
+
</div>
|
837
|
+
<div class="entry-description">
|
838
|
+
<span class="entry-version">
|
839
|
+
<a href="/ja/1.9.2/method/String/i/sub=21.html">1.9.2</a>
|
840
|
+
</span>
|
841
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>1}") # NG
|
842
|
+
'abbbcd'.sub!(/a(b+)/, "\1") # NG
|
843
|
+
'abbbcd'.sub!(/a(b+)/, "\\1") # OK
|
844
|
+
'abbbcd'.sub!(/a(b+)/, '\\1') # OK
|
845
|
+
'abbbcd'.sub!(/a(b+)/, '\1') # OK
|
846
|
+
'abbbcd'.sub!(/a(b+)/) { $1 } # OK これがもっとも安全
|
847
|
+
|
848
|
+
@see String#<span class="keyword">gsub</span>
|
849
|
+
|
850
|
+
<span class="separator">...</span></div></div>
|
851
|
+
</div>
|
852
|
+
<ul class="entry-metadata">
|
853
|
+
<li class="entry-type">
|
854
|
+
<span class="entry-instance-method">
|
855
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
856
|
+
</span>
|
857
|
+
</li>
|
858
|
+
</ul>
|
859
|
+
<ul class="entry-related-entries">
|
860
|
+
<li class="entry-related-entry-query">
|
861
|
+
<a href="/version:1.9.2/query:Kernel%24%27/">Kernel$'</a>
|
862
|
+
</li>
|
863
|
+
<li class="entry-related-entry-query">
|
864
|
+
<a href="/version:1.9.2/query:Kernel%24%2B/">Kernel$+</a>
|
865
|
+
</li>
|
866
|
+
<li class="entry-related-entry-query">
|
867
|
+
<a href="/version:1.9.2/query:Kernel%241/">Kernel$1</a>
|
868
|
+
</li>
|
869
|
+
<li class="entry-related-entry-query">
|
870
|
+
<a href="/version:1.9.2/query:Kernel%24%60/">Kernel$`</a>
|
871
|
+
</li>
|
872
|
+
<li class="entry-related-entry-class">
|
873
|
+
<a href="./class:String/">String</a>
|
874
|
+
</li>
|
875
|
+
<li class="entry-related-entry-query">
|
876
|
+
<a href="/version:1.9.2/query:String%23gsub/">String#gsub</a>
|
877
|
+
</li>
|
878
|
+
</ul>
|
879
|
+
<dt class="entry-name">
|
880
|
+
<a href="/ja/1.9.2/method/String/i/sub.html">String<wbr />#<wbr />sub(pattern) {|matched| <wbr />.<wbr /><wbr />.<wbr /><wbr />.<wbr /><wbr />.<wbr /> } -> String</a>
|
881
|
+
<span class="score">(13)</span>
|
882
|
+
</dt>
|
883
|
+
<dd>
|
884
|
+
<div class="entry-summary">
|
885
|
+
<p>
|
886
|
+
文字列中で pattern にマッチした最初の部分をブロックに渡し、
|
887
|
+
その評価結果で置き換えた新しい文字列を返します。
|
888
|
+
ブロックなしの sub と違い、ブロックの中からは
|
889
|
+
組み込み変数 $1, $2, $3, ... を問題なく参照できます。</p>
|
890
|
+
</div>
|
891
|
+
<div class="entry-description">
|
892
|
+
<span class="entry-version">
|
893
|
+
<a href="/ja/1.9.2/method/String/i/sub.html">1.9.2</a>
|
894
|
+
</span>
|
895
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>した。
|
896
|
+
しかし Ruby 1.8 以降では、その文字列そのものがパターンになります。
|
897
|
+
|
898
|
+
@param pattern 置き換える文字列のパターン
|
899
|
+
|
900
|
+
例:
|
901
|
+
|
902
|
+
p 'abcabc'.sub(/b/) {|s| s.upcase } #=> "aBcabc"
|
903
|
+
p 'abcabc'.sub(/b/) { $&.upcase } #=> "aBcabc"
|
904
|
+
|
905
|
+
@see String#<span class="keyword">gsub</span>
|
906
|
+
|
907
|
+
<span class="separator">...</span></div></div>
|
908
|
+
</div>
|
909
|
+
<ul class="entry-metadata">
|
910
|
+
<li class="entry-type">
|
911
|
+
<span class="entry-instance-method">
|
912
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
913
|
+
</span>
|
914
|
+
</li>
|
915
|
+
</ul>
|
916
|
+
<ul class="entry-related-entries">
|
917
|
+
<li class="entry-related-entry-query">
|
918
|
+
<a href="/version:1.9.2/query:Kernel%241/">Kernel$1</a>
|
919
|
+
</li>
|
920
|
+
<li class="entry-related-entry-class">
|
921
|
+
<a href="./class:String/">String</a>
|
922
|
+
</li>
|
923
|
+
<li class="entry-related-entry-query">
|
924
|
+
<a href="/version:1.9.2/query:String%23gsub/">String#gsub</a>
|
925
|
+
</li>
|
926
|
+
</ul>
|
927
|
+
<dt class="entry-name">
|
928
|
+
<a href="/ja/1.9.2/method/String/i/sub.html">String<wbr />#<wbr />sub(pattern<wbr />,<wbr /> replace) -> String</a>
|
929
|
+
<span class="score">(13)</span>
|
930
|
+
</dt>
|
931
|
+
<dd>
|
932
|
+
<div class="entry-summary">
|
933
|
+
<p>
|
934
|
+
文字列中で pattern にマッチした最初の部分を
|
935
|
+
文字列 replace で置き換えた文字列を生成し返します。</p>
|
936
|
+
</div>
|
937
|
+
<div class="entry-description">
|
938
|
+
<span class="entry-version">
|
939
|
+
<a href="/ja/1.9.2/method/String/i/sub.html">1.9.2</a>
|
940
|
+
</span>
|
941
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>実に防止し、コードの可読性を上げるには、
|
942
|
+
\& や \1 よりも下記のようにブロック付き形式の sub を使うべきです。
|
943
|
+
|
944
|
+
p 'xbbb-xbbb'.sub(/x(b+)/) { $1 } # => "bbb-xbbb" # OK
|
945
|
+
|
946
|
+
puts '\n'.sub(/\\/) { '\\\\' } # => \\n # OK
|
947
|
+
|
948
|
+
@see String#<span class="keyword">gsub</span>
|
949
|
+
|
950
|
+
<span class="separator">...</span></div></div>
|
951
|
+
</div>
|
952
|
+
<ul class="entry-metadata">
|
953
|
+
<li class="entry-type">
|
954
|
+
<span class="entry-instance-method">
|
955
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
956
|
+
</span>
|
957
|
+
</li>
|
958
|
+
</ul>
|
959
|
+
<ul class="entry-related-entries">
|
960
|
+
<li class="entry-related-entry-query">
|
961
|
+
<a href="/version:1.9.2/query:Kernel%24%27/">Kernel$'</a>
|
962
|
+
</li>
|
963
|
+
<li class="entry-related-entry-query">
|
964
|
+
<a href="/version:1.9.2/query:Kernel%24%2B/">Kernel$+</a>
|
965
|
+
</li>
|
966
|
+
<li class="entry-related-entry-query">
|
967
|
+
<a href="/version:1.9.2/query:Kernel%241/">Kernel$1</a>
|
968
|
+
</li>
|
969
|
+
<li class="entry-related-entry-query">
|
970
|
+
<a href="/version:1.9.2/query:Kernel%24%60/">Kernel$`</a>
|
971
|
+
</li>
|
972
|
+
<li class="entry-related-entry-class">
|
973
|
+
<a href="./class:String/">String</a>
|
974
|
+
</li>
|
975
|
+
<li class="entry-related-entry-query">
|
976
|
+
<a href="/version:1.9.2/query:String%23gsub/">String#gsub</a>
|
977
|
+
</li>
|
978
|
+
</ul>
|
979
|
+
<dt class="entry-name">
|
980
|
+
<a href="/ja/1.9.2/method/Net=3a=3aIMAP/i/append.html">Net<wbr />::<wbr />IMAP<wbr />#<wbr />append(mailbox<wbr />,<wbr /> message<wbr />,<wbr /> flags = nil<wbr />,<wbr /> date<wbr />_<wbr />time = nil)</a>
|
981
|
+
<span class="score">(12)</span>
|
982
|
+
</dt>
|
983
|
+
<dd>
|
984
|
+
<div class="entry-summary">
|
985
|
+
<p>
|
986
|
+
Sends a APPEND command to append the message to the end of
|
987
|
+
the mailbox.</p>
|
988
|
+
</div>
|
989
|
+
<div class="entry-description">
|
990
|
+
<span class="entry-version">
|
991
|
+
<a href="/ja/1.9.2/method/Net=3a=3aIMAP/i/append.html">1.9.2</a>
|
992
|
+
</span>
|
993
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>
|
994
|
+
Sends a APPEND command to append the message to the end of
|
995
|
+
the mailbox.
|
996
|
+
|
997
|
+
ex).
|
998
|
+
|
999
|
+
imap.append("inbox", <<EOF.<span class="keyword">gsub</span>(/\n/, "\r\n"), [:Seen], Time.now)
|
1000
|
+
Subject: hello
|
1001
|
+
From: shugo@ruby-lang.org
|
1002
|
+
To: shugo@ruby-lang.org
|
1003
|
+
|
1004
|
+
hello world
|
1005
|
+
EOF
|
1006
|
+
|
1007
|
+
<span class="separator">...</span></div></div>
|
1008
|
+
</div>
|
1009
|
+
<ul class="entry-metadata">
|
1010
|
+
<li class="entry-type">
|
1011
|
+
<span class="entry-instance-method">
|
1012
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
1013
|
+
</span>
|
1014
|
+
</li>
|
1015
|
+
</ul>
|
1016
|
+
<ul class="entry-related-entries">
|
1017
|
+
<li class="entry-related-entry-class">
|
1018
|
+
<a href="./class:Net%3A%3AIMAP/">Net::IMAP</a>
|
1019
|
+
</li>
|
1020
|
+
</ul>
|
1021
|
+
<dt class="entry-name">
|
1022
|
+
<a href="/ja/1.9.2/method/String/i/encode=21.html">String<wbr />#<wbr />encode!(encoding<wbr />,<wbr /> from<wbr />_<wbr />encoding<wbr />,<wbr /> options = nil) -> self</a>
|
1023
|
+
<span class="score">(12)</span>
|
1024
|
+
</dt>
|
1025
|
+
<dd>
|
1026
|
+
<div class="entry-summary">
|
1027
|
+
<p>
|
1028
|
+
self を指定したエンコーディングに変換し、自身を置き換えます。引数を2つ
|
1029
|
+
与えた場合、第二引数は変換元のエンコーディングを意味します。さもなくば
|
1030
|
+
self のエンコーディングが使われます。変換後の self を返します。</p>
|
1031
|
+
</div>
|
1032
|
+
<div class="entry-description">
|
1033
|
+
<span class="entry-version">
|
1034
|
+
<a href="/ja/1.9.2/method/String/i/encode=21.html">1.9.2</a>
|
1035
|
+
</span>
|
1036
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>コーディングを意味します。さもなくば
|
1037
|
+
self のエンコーディングが使われます。変換後の self を返します。
|
1038
|
+
|
1039
|
+
(<span class="keyword">gsub</span>!などと異なり)変換が行なわれなくても self を返します。
|
1040
|
+
|
1041
|
+
@param encoding 変換先のエンコーディングを表す文<span class="separator">...</span></div></div>
|
1042
|
+
</div>
|
1043
|
+
<ul class="entry-metadata">
|
1044
|
+
<li class="entry-type">
|
1045
|
+
<span class="entry-instance-method">
|
1046
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
1047
|
+
</span>
|
1048
|
+
</li>
|
1049
|
+
</ul>
|
1050
|
+
<ul class="entry-related-entries">
|
1051
|
+
<li class="entry-related-entry-class">
|
1052
|
+
<a href="./class:String/">String</a>
|
1053
|
+
</li>
|
1054
|
+
<li class="entry-related-entry-query">
|
1055
|
+
<a href="/version:1.9.2/query:String%23encode/">String#encode</a>
|
1056
|
+
</li>
|
1057
|
+
</ul>
|
1058
|
+
<p class="jump-to-top"><a href="#top">絞り込み条件を変える</a></p>
|
1059
|
+
<dt class="entry-name">
|
1060
|
+
<a href="/ja/1.9.2/method/String/i/encode=21.html">String<wbr />#<wbr />encode!(encoding<wbr />,<wbr /> options = nil) -> self</a>
|
1061
|
+
<span class="score">(12)</span>
|
1062
|
+
</dt>
|
1063
|
+
<dd>
|
1064
|
+
<div class="entry-summary">
|
1065
|
+
<p>
|
1066
|
+
self を指定したエンコーディングに変換し、自身を置き換えます。引数を2つ
|
1067
|
+
与えた場合、第二引数は変換元のエンコーディングを意味します。さもなくば
|
1068
|
+
self のエンコーディングが使われます。変換後の self を返します。</p>
|
1069
|
+
</div>
|
1070
|
+
<div class="entry-description">
|
1071
|
+
<span class="entry-version">
|
1072
|
+
<a href="/ja/1.9.2/method/String/i/encode=21.html">1.9.2</a>
|
1073
|
+
</span>
|
1074
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>コーディングを意味します。さもなくば
|
1075
|
+
self のエンコーディングが使われます。変換後の self を返します。
|
1076
|
+
|
1077
|
+
(<span class="keyword">gsub</span>!などと異なり)変換が行なわれなくても self を返します。
|
1078
|
+
|
1079
|
+
@param encoding 変換先のエンコーディングを表す文<span class="separator">...</span></div></div>
|
1080
|
+
</div>
|
1081
|
+
<ul class="entry-metadata">
|
1082
|
+
<li class="entry-type">
|
1083
|
+
<span class="entry-instance-method">
|
1084
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
1085
|
+
</span>
|
1086
|
+
</li>
|
1087
|
+
</ul>
|
1088
|
+
<ul class="entry-related-entries">
|
1089
|
+
<li class="entry-related-entry-class">
|
1090
|
+
<a href="./class:String/">String</a>
|
1091
|
+
</li>
|
1092
|
+
<li class="entry-related-entry-query">
|
1093
|
+
<a href="/version:1.9.2/query:String%23encode/">String#encode</a>
|
1094
|
+
</li>
|
1095
|
+
</ul>
|
1096
|
+
<dt class="entry-name">
|
1097
|
+
<a href="/ja/1.9.2/library/getoptlong.html">getoptlong</a>
|
1098
|
+
<span class="score">(12)</span>
|
1099
|
+
</dt>
|
1100
|
+
<dd>
|
1101
|
+
<div class="entry-summary">
|
1102
|
+
<p>getoptlong は、GNU の getopt_long() とまったく同じ方式でコマンド
|
1103
|
+
行オプションの解析を行う Ruby のライブラリです。</p>
|
1104
|
+
</div>
|
1105
|
+
<div class="entry-description">
|
1106
|
+
<span class="entry-version">
|
1107
|
+
<a href="/ja/1.9.2/library/getoptlong.html">1.9.2</a>
|
1108
|
+
</span>
|
1109
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>あなたのプログラム
|
1110
|
+
に足して下さい。
|
1111
|
+
|
1112
|
+
begin
|
1113
|
+
parser.each_option do |name, arg|
|
1114
|
+
eval "$OPT_#{name.sub(/^--/, '').<span class="keyword">gsub</span>(/-/, '_').upcase} = '#{arg}'"
|
1115
|
+
end
|
1116
|
+
rescue
|
1117
|
+
exit(1)
|
1118
|
+
end
|
1119
|
+
|
1120
|
+
each_option メソッドは、常にオプション名を「正式名 (<span class="separator">...</span></div></div>
|
1121
|
+
</div>
|
1122
|
+
<ul class="entry-metadata">
|
1123
|
+
<li class="entry-type">
|
1124
|
+
<span class="entry-library">
|
1125
|
+
<a href="./type:library/">ライブラリ</a>
|
1126
|
+
</span>
|
1127
|
+
</li>
|
1128
|
+
</ul>
|
1129
|
+
<ul class="entry-related-entries">
|
1130
|
+
<li class="entry-related-entry-query">
|
1131
|
+
<a href="/version:1.9.2/query:GetoptLong/">GetoptLong</a>
|
1132
|
+
</li>
|
1133
|
+
<li class="entry-related-entry-query">
|
1134
|
+
<a href="/version:1.9.2/query:GetoptLong%3A%3AAmbiguousOption/">GetoptLong::AmbiguousOption</a>
|
1135
|
+
</li>
|
1136
|
+
<li class="entry-related-entry-query">
|
1137
|
+
<a href="/version:1.9.2/query:GetoptLong%3A%3AError/">GetoptLong::Error</a>
|
1138
|
+
</li>
|
1139
|
+
<li class="entry-related-entry-query">
|
1140
|
+
<a href="/version:1.9.2/query:GetoptLong%3A%3AInvalidOption/">GetoptLong::InvalidOption</a>
|
1141
|
+
</li>
|
1142
|
+
<li class="entry-related-entry-query">
|
1143
|
+
<a href="/version:1.9.2/query:GetoptLong%3A%3AMissingArgument/">GetoptLong::MissingArgument</a>
|
1144
|
+
</li>
|
1145
|
+
<li class="entry-related-entry-query">
|
1146
|
+
<a href="/version:1.9.2/query:GetoptLong%3A%3ANeedlessArgument/">GetoptLong::NeedlessArgument</a>
|
1147
|
+
</li>
|
1148
|
+
</ul>
|
1149
|
+
<dt class="entry-name">
|
1150
|
+
<a href="/ja/1.9.2/doc/news=2f1=2e6=2e0.html">ruby 1<wbr />.<wbr />6 feature</a>
|
1151
|
+
<span class="score">(12)</span>
|
1152
|
+
</dt>
|
1153
|
+
<dd>
|
1154
|
+
<div class="entry-summary">
|
1155
|
+
<p>ruby 1.6 feature
|
1156
|
+
ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン
|
1157
|
+
になります。</p>
|
1158
|
+
</div>
|
1159
|
+
<div class="entry-description">
|
1160
|
+
<span class="entry-version">
|
1161
|
+
<a href="/ja/1.9.2/doc/news=2f1=2e6=2e0.html">1.9.2</a>
|
1162
|
+
</span>
|
1163
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span>,1].class
|
1164
|
+
p Foo.new("foo").succ.class
|
1165
|
+
p Foo.new("foo").reverse.class
|
1166
|
+
p((Foo.new("foo") * 5).class)
|
1167
|
+
p Foo.new("foo").<span class="keyword">gsub</span>(/foo/, "bar").class
|
1168
|
+
p Foo.new("foo").sub(/foo/, "bar").class
|
1169
|
+
p Foo.new("foo").ljust(10).class
|
1170
|
+
p Foo.new("foo").rjust(10).cl<span class="separator">...</span></div></div>
|
1171
|
+
</div>
|
1172
|
+
<ul class="entry-metadata">
|
1173
|
+
<li class="entry-type">
|
1174
|
+
<span class="entry-document">
|
1175
|
+
<a href="./type:document/">文書</a>
|
1176
|
+
</span>
|
1177
|
+
</li>
|
1178
|
+
</ul>
|
1179
|
+
<ul class="entry-related-entries">
|
1180
|
+
</ul>
|
1181
|
+
<dt class="entry-name">
|
1182
|
+
<a href="/ja/1.9.2/doc/news=2f1=2e8=2e4.html">ruby 1<wbr />.<wbr />8<wbr />.<wbr />4 feature</a>
|
1183
|
+
<span class="score">(12)</span>
|
1184
|
+
</dt>
|
1185
|
+
<dd>
|
1186
|
+
<div class="entry-summary">
|
1187
|
+
<p>ruby 1.8.4 feature
|
1188
|
+
ruby 1.8.4 での ruby 1.8.3 からの変更点です。</p>
|
1189
|
+
</div>
|
1190
|
+
<div class="entry-description">
|
1191
|
+
<span class="entry-version">
|
1192
|
+
<a href="/ja/1.9.2/doc/news=2f1=2e8=2e4.html">1.9.2</a>
|
1193
|
+
</span>
|
1194
|
+
<div class="snippets"><div class="snippet"><span class="separator">...</span> 28 09:21:49 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
1195
|
+
#
|
1196
|
+
# * lib/mkmf.rb (create_makefile): should not change sodir with
|
1197
|
+
# dir.<span class="keyword">gsub</span>!. (bccwin32 failed to install third party exntesions)
|
1198
|
+
# [ruby-dev:27834]
|
1199
|
+
#
|
1200
|
+
#なんとなく不要かな?
|
1201
|
+
#
|
1202
|
+
# EXTOUT を使わず、ext<span class="separator">...</span></div></div>
|
1203
|
+
</div>
|
1204
|
+
<ul class="entry-metadata">
|
1205
|
+
<li class="entry-type">
|
1206
|
+
<span class="entry-document">
|
1207
|
+
<a href="./type:document/">文書</a>
|
1208
|
+
</span>
|
1209
|
+
</li>
|
1210
|
+
</ul>
|
1211
|
+
<ul class="entry-related-entries">
|
1212
|
+
</ul>
|
1213
|
+
<dt class="entry-name">
|
1214
|
+
<a href="/ja/1.9.2/method/String/i/sub=21.html">String<wbr />#<wbr />sub!(pattern<wbr />,<wbr /> hash) -> String</a>
|
1215
|
+
<span class="score">(3)</span>
|
1216
|
+
</dt>
|
1217
|
+
<dd>
|
1218
|
+
<div class="entry-summary">
|
1219
|
+
<p>
|
1220
|
+
文字列中の pattern にマッチした部分をキーにして hash を引いた値で破壊的に置き換えます。</p>
|
1221
|
+
</div>
|
1222
|
+
<div class="entry-description">
|
1223
|
+
<span class="entry-version">
|
1224
|
+
<a href="/ja/1.9.2/method/String/i/sub=21.html">1.9.2</a>
|
1225
|
+
</span>
|
1226
|
+
<div class="snippets"></div>
|
1227
|
+
</div>
|
1228
|
+
<ul class="entry-metadata">
|
1229
|
+
<li class="entry-type">
|
1230
|
+
<span class="entry-instance-method">
|
1231
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
1232
|
+
</span>
|
1233
|
+
</li>
|
1234
|
+
</ul>
|
1235
|
+
<ul class="entry-related-entries">
|
1236
|
+
<li class="entry-related-entry-class">
|
1237
|
+
<a href="./class:String/">String</a>
|
1238
|
+
</li>
|
1239
|
+
</ul>
|
1240
|
+
<p class="jump-to-top"><a href="#top">絞り込み条件を変える</a></p>
|
1241
|
+
<dt class="entry-name">
|
1242
|
+
<a href="/ja/1.9.2/method/String/i/sub.html">String<wbr />#<wbr />sub(pattern<wbr />,<wbr /> hash) -> String</a>
|
1243
|
+
<span class="score">(3)</span>
|
1244
|
+
</dt>
|
1245
|
+
<dd>
|
1246
|
+
<div class="entry-summary">
|
1247
|
+
<p>
|
1248
|
+
文字列中の pattern にマッチした部分をキーにして hash を引いた値で置き換えます。</p>
|
1249
|
+
</div>
|
1250
|
+
<div class="entry-description">
|
1251
|
+
<span class="entry-version">
|
1252
|
+
<a href="/ja/1.9.2/method/String/i/sub.html">1.9.2</a>
|
1253
|
+
</span>
|
1254
|
+
<div class="snippets"></div>
|
1255
|
+
</div>
|
1256
|
+
<ul class="entry-metadata">
|
1257
|
+
<li class="entry-type">
|
1258
|
+
<span class="entry-instance-method">
|
1259
|
+
<a href="./type:instance-method/">インスタンスメソッド</a>
|
1260
|
+
</span>
|
1261
|
+
</li>
|
1262
|
+
</ul>
|
1263
|
+
<ul class="entry-related-entries">
|
1264
|
+
<li class="entry-related-entry-class">
|
1265
|
+
<a href="./class:String/">String</a>
|
1266
|
+
</li>
|
1267
|
+
</ul>
|
1268
|
+
</dd>
|
1269
|
+
</dl>
|
1270
|
+
</div>
|
1271
|
+
</div>
|
1272
|
+
|
1273
|
+
</div>
|
1274
|
+
<div class="footer">
|
1275
|
+
<p class="rurema">
|
1276
|
+
検索対象のドキュメントは
|
1277
|
+
<a href="http://redmine.ruby-lang.org/wiki/rurema">るりま</a>
|
1278
|
+
の成果物です。
|
1279
|
+
</p>
|
1280
|
+
<p class="powered-by">
|
1281
|
+
検索エンジンは
|
1282
|
+
<a href="http://groonga.org/">groonga</a>
|
1283
|
+
1.0.4
|
1284
|
+
を使っています。
|
1285
|
+
<p class="powered-by">
|
1286
|
+
groongaは
|
1287
|
+
<a href="http://groonga.rubyforge.org/">rroonga</a>
|
1288
|
+
1.0.8
|
1289
|
+
経由で利用しています。
|
1290
|
+
</p>
|
1291
|
+
<p class="powered-by">
|
1292
|
+
Powered by
|
1293
|
+
<a href="http://www.ruby-lang.org/">Ruby</a> 1.9.2.
|
1294
|
+
</p>
|
1295
|
+
<p class="powered-by">
|
1296
|
+
<a href="http://github.com/kou/rurema-search/">るりまサーチのリポジトリ</a>
|
1297
|
+
は
|
1298
|
+
<a href="http://github.com/">GitHub</a>
|
1299
|
+
上にあります。
|
1300
|
+
</p>
|
1301
|
+
</div>
|
1302
|
+
</body>
|
1303
|
+
</html>
|