るりまサーチ

最速Rubyリファレンスマニュアル検索!
1697件ヒット [1-100件を表示] (0.113秒)

別のキーワード

  1. _builtin -
  2. open-uri open
  3. irb/input-method new
  4. irb/input-method gets
  5. matrix -

ライブラリ

クラス

モジュール

キーワード

検索結果

<< 1 2 3 ... > >>

Kernel.#require(feature) -> bool (18226.0)

Ruby ライブラリ feature をロードします。拡張子補完を行い、 同じファイルの複数回ロードはしません。

...(/prime/).size # => 0
require
"prime" # => true
$LOADED_FEATURES.grep(/prime/).size # => 1
require
"prime" # => false
begin
require
"invalid"
rescue LoadError => e
e.message # => "cannot load such file -- invalid"
end
//}

@see Kernel.#load,Kernel.#autoload,Kernel.#require_relative...

Kernel.#require_relative(relative_feature) -> bool (6248.0)

現在のファイルからの相対パスで require します。

...現在のファイルからの相対パスで require します。

require
File.expand_path(relative_feature, File.dirname(__FILE__))
とほぼ同じです。

Kernel.#eval などで文字列を評価した場合に、そこから
require
_relative を呼出すと必ず失敗します。

@param r...
...elative_feature ファイル名の文字列です。
@raise LoadError ロードに失敗した場合に発生します。
@see Kernel.#require

=== require と load のスコープ

ローカル変数はファイル間では共有されません。ですので、
ロードしたライブラリのロ...
...せん。
このスコープの扱い方はKernel.#loadでも同様です。

//emlist[例][ruby]{
# ---------- some.rb -----------
$a = 1
@a = 1
A = 1
a = 1
# ---------- end some.rb -------

require
'some'
p $a #=> 1
p @a #=> 1
p A #=> 1
p a # undefined local variable or method `a' for #<Object:0x2...

Timeout.#timeout(sec, exception_class = nil) {|i| ... } -> object (161.0)

ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。

...します.
@param exception_class タイムアウトした時、発生させる例外を指定します.

例 長い計算のタイムアウト
require
'timeout'

def calc_pi(min)
loop do
x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end

t =...
...[1], min[0]*4.0/(min[0]+min[1])
#例
#=> 417519: pi = 3.141443

例 独自の例外を発生させるタイムアウト
#!/usr/bin/env ruby

require
'timeout'

class MYError < Exception;end
begin
Timeout.timeout(5, MYError) {
sleep(30)
}
rescue MYError => err
puts "MY...
...ものは実用レベルでは少ないのですが、
Socket などは DNSの名前解決に時間がかかった場合割り込めません
(resolv-replace を使用する必要があります)。
その処理を Ruby で実装しなおすか C 側で Ruby
のスレッドを意識してあげる...
...ッセージを指定します.省略した場合は
"execution expired" になります.

例 長い計算のタイムアウト
require
'timeout'

def calc_pi(min)
loop do
x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end

t =...

Timeout.#timeout(sec, exception_class, message) {|i| ... } -> object (161.0)

ブロックを sec 秒の期限付きで実行します。 ブロックの実行時間が制限を過ぎたときは例外 Timeout::Error が発生します。

...ッセージを指定します.省略した場合は
"execution expired" になります.

例 長い計算のタイムアウト
require
'timeout'

def calc_pi(min)
loop do
x = rand
y = rand
x**2 + y**2 < 1.0 ? min[0] += 1 : min[1] += 1
end
end

t =...
...[1], min[0]*4.0/(min[0]+min[1])
#例
#=> 417519: pi = 3.141443

例 独自の例外を発生させるタイムアウト
#!/usr/bin/env ruby

require
'timeout'

class MYError < Exception;end
begin
Timeout.timeout(5, MYError) {
sleep(30)
}
rescue MYError => err
puts "MY...
...ものは実用レベルでは少ないのですが、
Socket などは DNSの名前解決に時間がかかった場合割り込めません
(resolv-replace を使用する必要があります)。
その処理を Ruby で実装しなおすか C 側で Ruby
のスレッドを意識してあげる...

Kconv.#isjis(str) -> bool (157.0)

文字列 str が ISO-2022-JP なバイト列として正当であるかどうかを判定します。

...文字列 str が ISO-2022-JP なバイト列として正当であるかどうかを判定します。

@param str 判定対象の文字列
@see String#isjis

//emlist[例][ruby]{
require
'kconv'

euc_str = "\
\xa5\xaa\xa5\xd6\xa5\xb8\xa5\xa7\xa5\xaf\xa5\xc8\xbb\xd8\xb8\xfe\
\xa5\xd7\xa5\xed\xa5\xb0...
...\x52\x75\x62\x79".force_encoding('EUC-JP')

jis_str = "\
\x1b\x24\x42\x25\x2a\x25\x56\x25\x38\x25\x27\x25\x2f\x25\x48\x3b\x58\x38\x7e\
\x25\x57\x25\x6d\x25\x30\x25\x69\x25\x5f\x25\x73\x25\x30\x38\x40\x38\x6c\x1b\x28\x42\
\x52\x75\x62\x79".force_encoding('ISO-2022-JP')

euc_str.isjis # => false
jis_...

絞り込み条件を変える

WEBrick::Utils.#random_string(len) -> String (155.0)

A-Z, a-z, 0-9 からなる長さ len のランダムな文字列を返します。

...A-Z, a-z, 0-9 からなる長さ len のランダムな文字列を返します。

@param len 得たい文字列の長さを整数で指定します。単位はバイトです。

require
'webrick'
p WEBrick::Utils.random_string(10) #=> "xF0jwU4RJd"...

Readline.#readline(prompt = "", add_hist = false) -> String | nil (149.0)

prompt を出力し、ユーザからのキー入力を待ちます。 エンターキーの押下などでユーザが文字列を入力し終えると、 入力した文字列を返します。 このとき、add_hist が true であれば、入力した文字列を入力履歴に追加します。 何も入力していない状態で EOF(UNIX では ^D) を入力するなどで、 ユーザからの入力がない場合は nil を返します。

...、かつ、標準入力をクローズしている
(isatty(2) の errno が EBADF である。) 場合に発生します。

例:

require
"readline"

input = Readline.readline
(プロンプトなどは表示せずに、入力待ちの状態になります。
ここでは「...
...

require
'readline'

stty_save = `stty -g`.chomp
begin
while buf = Readline.readline
p buf
end
rescue Interrupt
system("stty", stty_save)
exit
end

例: INTシグナルを捕捉して、端末状態を復帰する。

require
'readline'

stty_save = `stty -g`.c...
...ります。

require
'readline'

trap("INT", "SIG_IGN")

while buf = Readline.readline
p buf
end

入力履歴 Readline::HISTORY を使用して、次のようなこともできます。

例: 空行や直前の入力と同じ内容は入力履歴に残さない。

require
'readline'...

Kernel.#open(name, mode = &#39;r&#39;, perm = nil, options = {}) -> StringIO | Tempfile | IO (137.0)

name が http:// や ftp:// で始まっている文字列なら URI のリソースを 取得した上で StringIO オブジェクトまたは Tempfile オブジェクトとして返します。 返されるオブジェクトは OpenURI::Meta モジュールで extend されています。

...モジュールで extend されています。

Ruby2.7以降、open-uriにより拡張されたKernel.openでURLを開くときにwarningが表示されるようになりました。

require
'open-uri'
open("http://www.ruby-lang.org/") {|f|
# ...
}
#=> warning: calling URI.open via Ke...
...Net::FTPError のサブクラスが発生します。詳しくは net/ftp
を参照して下さい。

例:

require
'open-uri'
sio = open('http://www.example.com') { |sio|
p sio.is_a?(OpenURI::Meta) # => true
p sio.content_type
puts sio.read
}

@s...

Kernel.#open(name, mode = &#39;r&#39;, perm = nil, options = {}) {|ouri| ...} -> object (137.0)

name が http:// や ftp:// で始まっている文字列なら URI のリソースを 取得した上で StringIO オブジェクトまたは Tempfile オブジェクトとして返します。 返されるオブジェクトは OpenURI::Meta モジュールで extend されています。

...モジュールで extend されています。

Ruby2.7以降、open-uriにより拡張されたKernel.openでURLを開くときにwarningが表示されるようになりました。

require
'open-uri'
open("http://www.ruby-lang.org/") {|f|
# ...
}
#=> warning: calling URI.open via Ke...
...Net::FTPError のサブクラスが発生します。詳しくは net/ftp
を参照して下さい。

例:

require
'open-uri'
sio = open('http://www.example.com') { |sio|
p sio.is_a?(OpenURI::Meta) # => true
p sio.content_type
puts sio.read
}

@s...

LUSolve.#lusolve(a, b, ps, zero = 0.0) -> [BigDecimal] (137.0)

LU 分解を用いて、連立1次方程式 Ax = b の解 x を求めて返します。

...立1次方程式 Ax = b の解 x を求めて返します。

@param a 行列を BigDecimal の配列で指定します。
各要素を Row-major order で並べて 1 次元の配列にし、
LUSolve.#ludecomp で変換したものを指定します。

@param b ベクトルを Big...
...zero 0.0 を表す値を指定します。

//emlist[][ruby]{
require
'bigdecimal'
require
'bigdecimal/util'
require
'bigdecimal/ludcmp'

include LUSolve

a = [['1.0', '2.0'], ['3.0', '1.0']].flatten.map(&:to_d)
# x = ['1.0', -1.0']
b = ['-1.0', '2.0'].map(&:to_d)

zero = '0.0'.to_d
one = '1.0'.to_d...
...# 以下の 2 行は
ps = ludecomp(a, b.size, zero, one) # a が破壊的に変更される
x = lusolve(a, b, ps, zero)
# こう書いてもよい
# x = lusolve(a, b, ludecomp(a, b.size, zero, one), zero)

p x.map(&:to_f) #=> [1.0, -1.0]
//}...

絞り込み条件を変える

Etc.#uname -> {Symbol => String} (131.0)

uname(2) で取得したシステム情報を Hash で返します。

...machine の
5 つのキーを持つ Hash を返します。

//emlist[例][ruby]{
require
'etc'
require
'pp'

pp Etc.uname
# => {:sysname=>"Linux",
# :nodename=>"boron",
# :release=>"2.6.18-6-xen-686",
# :version=>"#1 SMP Thu Nov 5 19:54:42 UTC 2009",
# :machine=>"i686"}
//}...
<< 1 2 3 ... > >>