
![条件を削除 [x]](/ja/search/images/drop-condition-icon.png)
ライブラリ
- English (90)
- ビルトイン (124)
- csv (9)
- drb (10)
- fileutils (10)
- pathname (30)
- rake (93)
-
rake
/ (9)loaders / makefile -
rake
/ (144)packagetask
クラス
- Array (40)
- NameError (10)
- Object (10)
- Pathname (30)
- Proc (10)
-
Rake
:: (10)Application -
Rake
:: (10)FileList -
Rake
:: (9)MakefileLoader -
Rake
:: (10)NameSpace -
Rake
:: (144)PackageTask - Random (30)
モジュール
- FileUtils (10)
- Kernel (104)
- ObjectSpace (10)
-
Rake
:: (27)TaskManager - RakeFileUtils (36)
キーワード
-
$ (10)ARGV -
$ (10)DEFAULT _ INPUT -
$ (10)ERROR _ INFO -
$ (10)ERROR _ POSITION -
$ (10)INPUT _ LINE _ NUMBER -
$ (10)LAST _ PAREN _ MATCH -
$ (10)NR -
$ (10)ORS -
$ (10)OUTPUT _ RECORD _ SEPARATOR -
1
. (10)6 . 8から1 . 8 . 0への変更点(まとめ) - CSV (9)
- DRbProtocol (10)
-
NEWS for Ruby 2
. (10)0 . 0 -
NEWS for Ruby 2
. (10)3 . 0 - abort (14)
-
add
_ (10)loader -
bigdecimal
/ (10)ludcmp -
bigdecimal
/ (10)newton - binding (10)
-
cgi
/ (10)session -
cp
_ (10)r - delete (10)
- egrep (10)
- find (10)
-
in
_ (9)namespace - intern (9)
- irb (10)
- load (9)
- logger (10)
- name (9)
- name= (9)
-
need
_ (9)tar -
need
_ (9)tar= -
need
_ (9)tar _ bz2 -
need
_ (9)tar _ bz2= -
need
_ (9)tar _ gz -
need
_ (9)tar _ gz= -
need
_ (9)zip -
need
_ (9)zip= - new (19)
-
nowrite
_ (9)flag -
nowrite
_ (9)flag= - optparse (10)
-
package
_ (9)dir -
package
_ (9)dir= -
package
_ (9)dir _ path -
package
_ (9)files -
package
_ (9)files= - profile (3)
- rand (30)
- receiver (10)
-
respond
_ (10)to _ missing? -
rinda
/ (10)rinda - rss (10)
-
ruby 1
. (10)8 . 4 feature - split (10)
-
synthesize
_ (9)file _ task -
undefine
_ (10)finalizer - unlink (10)
-
verbose
_ (9)flag -
verbose
_ (9)flag=
検索結果
先頭5件
-
Array
# (18128.0)sample -> object | nil -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
..._a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}
random SecureRandom などの乱数生成器を渡すことができます。
//emlist[例][ruby]{
require 'securerandom'
a = (1..10).to_a
p a.sample(rando... -
Array
# (18128.0)sample(n) -> Array -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
..._a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}
random SecureRandom などの乱数生成器を渡すことができます。
//emlist[例][ruby]{
require 'securerandom'
a = (1..10).to_a
p a.sample(rando... -
Array
# (18128.0)sample(n , random: Random) -> Array -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
..._a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}
random SecureRandom などの乱数生成器を渡すことができます。
//emlist[例][ruby]{
require 'securerandom'
a = (1..10).to_a
p a.sample(rando... -
Array
# (18128.0)sample(random: Random) -> object | nil -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
..._a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}
random SecureRandom などの乱数生成器を渡すことができます。
//emlist[例][ruby]{
require 'securerandom'
a = (1..10).to_a
p a.sample(rando... -
Array
# (18122.0)sample -> object | nil -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
...を指定した場合に発生します。
@raise ArgumentError 引数 n に負の数を指定した場合に発生します。
例:
a = (1..10).to_a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]......した場合に発生します。
@raise ArgumentError 引数 n に負の数を指定した場合に発生します。
//emlist[例][ruby]{
a = (1..10).to_a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}... -
Array
# (18122.0)sample(n) -> Array -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
...を指定した場合に発生します。
@raise ArgumentError 引数 n に負の数を指定した場合に発生します。
例:
a = (1..10).to_a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]......した場合に発生します。
@raise ArgumentError 引数 n に負の数を指定した場合に発生します。
//emlist[例][ruby]{
a = (1..10).to_a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}... -
Array
# (18122.0)sample(n , random: Random) -> Array -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
...を指定した場合に発生します。
@raise ArgumentError 引数 n に負の数を指定した場合に発生します。
例:
a = (1..10).to_a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]......した場合に発生します。
@raise ArgumentError 引数 n に負の数を指定した場合に発生します。
//emlist[例][ruby]{
a = (1..10).to_a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}... -
Array
# (18122.0)sample(random: Random) -> object | nil -
配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。
...を指定した場合に発生します。
@raise ArgumentError 引数 n に負の数を指定した場合に発生します。
例:
a = (1..10).to_a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]......した場合に発生します。
@raise ArgumentError 引数 n に負の数を指定した場合に発生します。
//emlist[例][ruby]{
a = (1..10).to_a
p a.sample #=> 9
p a.sample #=> 10
p a.sample(3) #=> [1, 9, 3]
p a #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
//}... -
optparse (192.0)
-
コマンドラインのオプションを取り扱うためのライブラリです。
...opt = OptionParser.new
opt.on('-a') {|v| p v }
opt.on('-b') {|v| p v }
opt.parse!(ARGV)
p ARGV
ruby sample.rb -a foo bar -b baz
# => true
true
["foo", "bar", "baz"]
OptionParser#on メソッドの引数でオプショ......)。ただし、環境変数 POSIXLY_CORRECT が定義してあると
この挙動は変更されます。
env POSIXLY_CORRECT=1 ruby ./sample.rb -a foo bar -b baz
# => true # -a はオプションと解釈
["foo", "bar", "-b", "baz"]......V)
p argv
定義していないオプションを指定すると例外
OptionParser::InvalidOption が発生します。
ruby ./sample.rb -c
/usr/local/lib/ruby/1.9/optparse.rb:1428:in `complete': invalid option: -c (OptionParser::InvalidOption)
from /usr/l......b を受け付けるコマンドを作成する例です。
//emlist[sample.rb][ruby]{
require 'optparse'
opt = OptionParser.new
opt.on('-a') {|v| p v }
opt.on('-b') {|v| p v }
opt.parse!(ARGV)
p ARGV
//}
↓
ruby sample.rb -a foo bar -b baz
# => true
true......ser#parse! では、ARGV からオプションが取り除かれます。
これを避けるには OptionParser#parse を使います。
//emlist[sample.rb][ruby]{
require 'optparse'
opt = OptionParser.new
opt.on('-a') {|v| p v }
opt.on('-b') {|v| p v }
# parse() の場合、ARGVは変更され... -
rss (126.0)
-
RSS を扱うためのライブラリです。
...],
]
全てのキーは省略可能です.
例えば,xml-stylesheetとしてsample.xslを指定する場合は以下の
ようにします.
rss.xml_stylesheets << RSS::XMLStyleSheet.new({:href => "sample.xsl"})
本当は{:type => "text/xsl"}も指定しないといけないとこ
ろ......nnel.description = "Example Site"
maker.channel.link = "http://example.com/"
end
もし,
* http://example.com/article.htmlにある
* Sample Articleというタイトルの
エントリを含めたければ以下のようにします.
require "rss"
rss = RSS::Maker.make("1.0")......maker.channel.link = "http://example.com/"
item = maker.items.new_item
item.link = "http://example.com/article.html"
item.title = "Sample Article"
end
===== 更新時刻を追加
もし,先のエントリが
* 2004/11/1 10:10
のものならこうします.
require "rs... -
Object
# (60.0)respond _ to _ missing?(symbol , include _ private) -> bool -
自身が symbol で表されるメソッドに対し BasicObject#method_missing で反応するつもりならば真を返します。
...class Sample
def method_missing(name, *args)
if name =~ /^to_*/
[name, *args] # => [:to_sample, "sample args1", "sample args2"]
return
else
super
end
end
def respond_to_missing?(sym, include_private)
(sym =~ /^to_*/) ? true : super
end
end
s = Sample.new......s.to_sample("sample args1", "sample args2")
s.respond_to?(:to_sample) # => true
s.respond_to?(:sample) # => false
//}
@see Object#respond_to?, BasicObject#method_missing... -
Rake
:: (60.0)FileList # egrep(pattern) {|filename , count , line| . . . } -
与えられたパターンをファイルリストから grep のように検索します。
...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(/.*/)......=> "filename = sample1, count = 1, line = line1\n"
# => "filename = sample1, count = 2, line = line2\n"
# => "filename = sample1, count = 3, line = line3\n"
# => "filename = sample2, count = 1, line = line1\n"
# => "filename = sample2, count = 2, line = line2\n"
# => "filename = sample2, count = 3,......line = line3\n"
# => "filename = sample2, count = 4, line = line4\n"
//}... -
ObjectSpace
. (36.0)# undefine _ finalizer(obj) -> object -
obj に対するファイナライザをすべて解除します。 obj を返します。
...][ruby]{
class Sample
def Sample.callback
proc {
puts "finalize"
}
end
def initialize
ObjectSpace.define_finalizer(self, Sample.callback)
end
def undef
ObjectSpace.undefine_finalizer(self)
end
end
Sample.new
GC.start
# => finalize
Sample.new
sample.undef
GC.star... -
Rake
:: (24.0)MakefileLoader # load(filename) -
与えられた Makefile をロードします。
...open "sample.mf", "w" do |io|
io << <<-'SAMPLE_MF'
# Comments
a: a1 a2 a3 a4
b: b1 b2 b3 \
b4 b5 b6\
# Mid: Comment
b7
a : a5 a6 a7
c: c1
d: d1 d2 \
e f : e1 f1
g\ 0: g1 g\ 2 g\ 3 g4
SAMPLE_MF
end
task :test_rake_app do |task|
loader = Rake::MakefileLoader.new
loader.load("sample.mf")... -
Rake
:: (24.0)TaskManager # synthesize _ file _ task(task _ name) -> Rake :: FileTask | nil -
与えられたタスク名をもとにファイルタスクを合成します。
...by]{
# Rakefile での記載例とする
task default: :test_rake_app
task :test_rake_app do |task|
task.application.synthesize_file_task("sample_file") # => nil
IO.write("sample_file", "")
task.application.synthesize_file_task("sample_file") # => <Rake::FileTask sample_file => []>
end
//}...