種類
- インスタンスメソッド (74)
- 文書 (47)
- 特異メソッド (36)
- モジュール関数 (36)
- ライブラリ (12)
クラス
- CSV (72)
-
CSV
:: FieldInfo (24) -
RubyVM
:: AbstractSyntaxTree :: Node (14)
モジュール
- Kernel (36)
キーワード
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (12) -
NEWS for Ruby 2
. 2 . 0 (11) - caller (36)
- convert (36)
-
first
_ column (7) -
first
_ lineno (7) - header (12)
- index (12)
- new (12)
- rss (12)
-
ruby 1
. 6 feature (12) -
ruby 1
. 8 . 2 feature (12)
検索結果
先頭5件
-
CSV
. parse(str , options = Hash . new) -> Array (18150.0) -
このメソッドは文字列を簡単にパースすることができます。 ブロックを与えた場合は、ブロックにそれぞれの行を渡します。 ブロックを省略した場合は、配列の配列を返します。
...'pp'
s = <<EOS
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
EOS
pp CSV.parse(s)
# => [["id", "first name", "last name", "age"],
# ["1", "taro", "tanaka", "20"],
# ["2", "jiro", "suzuki", "18"]]
CSV.parse(s, headers: true).each do |row|
p [row['first name'], row['age']]......=> ["taro", "20"]
# ["jiro", "18"]
//}
//emlist[例][ruby]{
require "csv"
csv = "id|first name|last name|age\n1|taro|tanaka|20\n2|jiro|suzuki|18"
CSV.parse(csv, col_sep: '|') do |row|
p [row[1], row[2]]
end
# => ["first name", "last name"]
# => ["taro", "tanaka"]
# => ["jiro", "suzuki"]
//}... -
CSV
. parse(str , options = Hash . new) {|row| . . . } -> nil (18150.0) -
このメソッドは文字列を簡単にパースすることができます。 ブロックを与えた場合は、ブロックにそれぞれの行を渡します。 ブロックを省略した場合は、配列の配列を返します。
...'pp'
s = <<EOS
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
EOS
pp CSV.parse(s)
# => [["id", "first name", "last name", "age"],
# ["1", "taro", "tanaka", "20"],
# ["2", "jiro", "suzuki", "18"]]
CSV.parse(s, headers: true).each do |row|
p [row['first name'], row['age']]......=> ["taro", "20"]
# ["jiro", "18"]
//}
//emlist[例][ruby]{
require "csv"
csv = "id|first name|last name|age\n1|taro|tanaka|20\n2|jiro|suzuki|18"
CSV.parse(csv, col_sep: '|') do |row|
p [row[1], row[2]]
end
# => ["first name", "last name"]
# => ["taro", "tanaka"]
# => ["jiro", "suzuki"]
//}... -
RubyVM
:: AbstractSyntaxTree :: Node # first _ column -> Integer (6113.0) -
ソースコード中で、self を表すテキストが最初に現れる列番号を返します。
...ソースコード中で、self を表すテキストが最初に現れる列番号を返します。
列番号は0-originで、バイト単位で表されます。
//emlist[][ruby]{
node = RubyVM::AbstractSyntaxTree.parse('1 + 2')
p node.first_column # => 0
//}... -
RubyVM
:: AbstractSyntaxTree :: Node # first _ lineno -> Integer (6113.0) -
ソースコード中で、self を表すテキストが最初に現れる行番号を返します。
...ソースコード中で、self を表すテキストが最初に現れる行番号を返します。
行番号は1-originです。
//emlist[][ruby]{
node = RubyVM::AbstractSyntaxTree.parse('1 + 2')
p node.first_lineno # => 1
//}... -
rss (276.0)
-
RSS を扱うためのライブラリです。
...p://purl.org/rss/1.0/spec
* RSS 2.0 http://www.rssboard.org/rss-specification
* Atom 1.0 https://www.ietf.org/rfc/rfc4287.txt
=== 注意
RSS ParserはRSS 0.9x/1.0/2.0, Atom 1.0 をサポートしていますが,RSS 0.90
はサポートしてません.ごめんなさい.
RSS のモジ......ールは content:encoded しかサポートしていません.
=== パース
RSS をパースしたい場合は RSS::Parser クラスを使います。
RSS::Parser.parse は String の RSSを パースします(使用するXMLパー
サによっては File や IO オブジェクトなどでも......(["My site", ...]など)
rss.channel.dc_titles.first.value == rss.channel.dc_title
# => true
# 厳密にはこう
first_title = rss.channel.dc_titles.first
first_title = first_title.value if first_title
first_title == rss.channel.dc_title... -
ruby 1
. 6 feature (78.0) -
ruby 1.6 feature ruby version 1.6 は安定版です。この版での変更はバグ修正がメイン になります。
...7 feature>)) の 2002-06-24 も参照)
p "#{ "" # comment }"
=> ruby 1.6.8 (2002-10-04) [i586-linux]
""
=> -:1: parse error
ruby 1.7.3 (2002-10-04) [i586-linux]
: SizedQueue#deq, #shift
: SizedQueue#enq
追加(push, pop の別名)。これらが定......ruby '-*' -v
=> ruby 1.6.7 (2002-03-01) [i586-linux]
=> ruby: invalid option -* (-h will show valid options)
: 2002-05-22 parsedate
バージョンアップ((<ruby-dev:17171>))
: 2002-05-22 -T オプション
ruby のコマンドラインオプション -T の後に......p /a#{Regexp.quote("#")}b/x =~ "ab"
=> -:3: warning: ambiguous first argument; make sure
ruby 1.6.7 (2002-03-01) [i586-linux]
"#"
0
=> -:3: warning: ambiguous first argument; make sure
ruby 1.6.7 (2002-07-30) [i586-linux]... -
CSV
. new(data , options = Hash . new) -> CSV (60.0) -
このメソッドは CSV ファイルを読み込んだり、書き出したりするために String か IO のインスタンスをラップします。
...the first line ending beyond this
size.) If a quote cannot be found within the limit CSV will raise a
MalformedCSVError, assuming the data is faulty. You can use this limit to
prevent what are effectively DoS attacks on the parser. However, this
limit can cause a legitimate parse to......列を返します。
: :headers
:first_row というシンボルか真を指定すると、CSV ファイルの一行目をヘッダとして扱います。
配列を指定するとそれをヘッダとして扱います。文字列を指定すると CSV.parse_line を
使用してパースし......v"
users =<<-EOS
id,first name,last name,age
1,taro,tanaka,20
2,jiro,suzuki,18
3,ami,sato,19
4,yumi,adachi,21
EOS
File.write("test.csv", users)
File.open("test.csv", "r") do |f|
csv = CSV.new(f, headers: true)
csv.class # => CSV
csv.first # => #<CSV::Row "id":"1" "first name":"taro" "last n... -
Kernel
. # caller(range) -> [String] | nil (48.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end
def foo
p parse_caller(caller.first)
end
def bar
foo
p parse_caller(caller.first)
end
bar
p parse_caller(caller.first)
#=> ["-", 15......, "bar"]
# ["-", 19, nil]
# nil
//}
以下は、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
def debug(*args)
p [caller.first, *args] if $DEBUG
end
debug "debug information"
#=> ["-:7", "debug information"]
//}... -
Kernel
. # caller(start = 1) -> [String] | nil (48.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end
def foo
p parse_caller(caller.first)
end
def bar
foo
p parse_caller(caller.first)
end
bar
p parse_caller(caller.first)
#=> ["-", 15......, "bar"]
# ["-", 19, nil]
# nil
//}
以下は、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
def debug(*args)
p [caller.first, *args] if $DEBUG
end
debug "debug information"
#=> ["-:7", "debug information"]
//}... -
Kernel
. # caller(start , length) -> [String] | nil (48.0) -
start 段上の呼び出し元の情報を $@ の形式のバックトレース(文字列の配列)として返します。
...[例][ruby]{
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = $1
line = $2.to_i
method = $3
[file, line, method]
end
end
def foo
p parse_caller(caller.first)
end
def bar
foo
p parse_caller(caller.first)
end
bar
p parse_caller(caller.first)
#=> ["-", 15......, "bar"]
# ["-", 19, nil]
# nil
//}
以下は、$DEBUG が真の場合に役に立つ debug 関数
のサンプルです。
//emlist[例][ruby]{
$DEBUG = true
def debug(*args)
p [caller.first, *args] if $DEBUG
end
debug "debug information"
#=> ["-:7", "debug information"]
//}...