るりまサーチ

最速Rubyリファレンスマニュアル検索!
741件ヒット [1-100件を表示] (0.022秒)
トップページ > クエリ:sample[x]

別のキーワード

  1. array sample
  2. _builtin sample
  3. sample array
  4. sample random

ライブラリ

モジュール

検索結果

<< 1 2 3 ... > >>

Array#sample -> object | nil (18122.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

...した場合に発生します。

@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#sample(n) -> Array (18122.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

...した場合に発生します。

@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#sample(n, random: Random) -> Array (18122.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

...した場合に発生します。

@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#sample(random: Random) -> object | nil (18122.0)

配列の要素を1個(引数を指定した場合は自身の要素数を越えない範囲で n 個) ランダムに選んで返します。

...した場合に発生します。

@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)

コマンドラインのオプションを取り扱うためのライブラリです。

...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...
...)。ただし、環境変数 POSIXLY_CORRECT が定義してあると
この挙動は変更されます。

env POSIXLY_CORRECT=1 ruby ./sample.rb -a foo bar -b baz
# => true # -a はオプションと解釈
["foo", "bar", "-b", "baz"]...
...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#respond_to_missing?(symbol, include_private) -> bool (60.0)

自身が 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::FileList#egrep(pattern) {|filename, count, line| ... } (60.0)

与えられたパターンをファイルリストから 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.#undefine_finalizer(obj) -> object (36.0)

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::MakefileLoader#load(filename) (24.0)

与えられた 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")...

絞り込み条件を変える

<< 1 2 3 ... > >>