ライブラリ
- ビルトイン (211)
-
rubygems
/ version (11) - thread (2)
- win32ole (11)
クラス
-
ARGF
. class (77) - BasicObject (22)
- Data (4)
- Exception (11)
-
Gem
:: Version (11) - Object (11)
-
WIN32OLE
_ TYPE (11)
モジュール
- Enumerable (66)
キーワード
- != (11)
-
1
. 6 . 8から1 . 8 . 0への変更点(まとめ) (11) - === (11)
- ConditionVariable (11)
- Marshal フォーマット (11)
-
NEWS for Ruby 2
. 0 . 0 (11) -
NEWS for Ruby 2
. 1 . 0 (11) -
NEWS for Ruby 2
. 3 . 0 (9) -
NEWS for Ruby 2
. 7 . 0 (5) -
NEWS for Ruby 3
. 0 . 0 (4) - Numeric (11)
- Requirement (11)
- Ruby用語集 (11)
-
default
_ event _ sources (11) - define (4)
- each (33)
-
each
_ line (44) - max (22)
- min (44)
- rdoc (11)
-
ruby 1
. 6 feature (11) -
ruby 1
. 8 . 2 feature (11) -
ruby 1
. 8 . 3 feature (11) -
ruby 1
. 8 . 4 feature (11) -
ruby 1
. 9 feature (11) - tracer (11)
- tsort (11)
-
webrick
/ cgi (11) - 制御構造 (11)
- 演算子式 (11)
検索結果
先頭5件
-
Exception
# ==(other) -> bool (21152.0) -
自身と指定された other のクラスが同じであり、 message と backtrace が == メソッドで比較して 等しい場合に true を返します。そうでない場合に false を返します。
...自身と指定された other のクラスが同じであり、
message と backtrace が == メソッドで比較して
等しい場合に true を返します。そうでない場合に false を返します。
@param other 自身と比較したいオブジェクトを指定します。......合は
Exception#exception を実行して変換を試みます。
//emlist[例][ruby]{
require "date"
def check_long_month(month)
return if Date.new(2000, month, -1).day == 31
raise "#{month} is not long month"
end
def get_exception
return begin
yield
rescue => e
e......ception { check_long_month(e) } }
p results.map { |e| e.class }
# => [RuntimeError, RuntimeError, RuntimeError]
p results.map { |e| e.message }
# => ["2 is not long month", "2 is not long month", "4 is not long month"]
# class, message, backtrace が同一のため true になる
p results[0] == re... -
BasicObject
# ==(other) -> bool (21118.0) -
オブジェクトが other と等しければ真を、さもなくば偽を返します。
...//emlist[例][ruby]{
class Person < BasicObject
def initialize(name, age)
@name = name
@age = age
end
end
tanaka1 = Person.new("tanaka", 24)
tanaka2 = Person.new("tanaka", 24)
tanaka1 == tanaka1 #=> true
tanaka1 == tanaka2 #=> false
//}
@see BasicObject#equal?, Object#==, Obje... -
Object
# ===(other) -> bool (12218.0) -
case 式で使用されるメソッドです。d:spec/control#case も参照してください。
...bject#== を呼び出します。
when 節の式をレシーバーとして === を呼び出すことに注意してください。
また Enumerable#grep でも使用されます。
@param other 比較するオブジェクトです。
//emlist[][ruby]{
age = 12
# (0..2).===(12), (3..6).===(12),......aby"
when 3 .. 6
"little child"
when 7 .. 12
"child"
when 13 .. 18
"youth"
else
"adult"
end
puts result #=> "child"
def check arg
case arg
when /ruby(?!\s*on\s*rails)/i
"hit! #{arg}"
when String
"Instance of String class. But don't hit."
else
"unknown"......end
end
puts check([]) #=> unknown
puts check("mash-up in Ruby on Rails") #=> instance of String class. But not hit...
puts check("<Ruby's world>") #=> hit! <Ruby's world>
//}
@see Object#==, Range#===, Module#===, Regexp#===, Enumerable#grep... -
Data
. define(*args) {|subclass| block } -> Class (6314.0) -
Data クラスに新しいサブクラスを作って、それを返します。
...ドが定義されています。
//emlist[例][ruby]{
Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)
p fred.name # => "Fred"
p fred.age # => 5
//}
メンバの値を書き換えることはできません。
//emlist[例][ruby]{
Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)......ンマッチに利用できます。
//emlist[例][ruby]{
class HTTPFetcher
Response = Data.define(:body)
NotFound = Data.define
def get(url)
# ダミーの実装
if url == "http://example.com/"
Response.new(body: "Current time is #{Time.now}")
else
NotFound.new
e......end
end
def fetch(url)
fetcher = HTTPFetcher.new
case fetcher.get(url)
in HTTPFetcher::Response(body)
body
in HTTPFetcher::NotFound
:NotFound
end
end
p fetch("http://example.com/") # => "Current time is 2023-01-10 10:00:53 +0900"
p fetch("http://example.com/404") # => :NotFo... -
ARGF
. class # each _ line(rs = $ / ) { |line| . . . } -> self (6218.0) -
ARGFの現在位置から 1 行ずつ文字列として読み込み、それを引数として与えら れたブロックを実行します。
...容を返します。現在の行についてファイル名や行数を得るには
ARGF.class#filename と ARGF.class#lineno を使用します。
@param rs 行の区切りを文字列で指定します。nil を指定すると行区切りなし
とみなします。空文字列 "" を......フモード)。
@param limit 各行の最大の読み込みバイト数
例: ARGFの各ファイル名(最初に1回のみ)、行番号、内容を表示
ARGF.each_line do |line|
puts ARGF.filename if ARGF.lineno == 1
puts "#{ARGF.lineno}: #{line}"
end
@see IO#each, IO#each_line... -
ARGF
. class # each _ line(rs = $ / , limit) { |line| . . . } -> self (6218.0) -
ARGFの現在位置から 1 行ずつ文字列として読み込み、それを引数として与えら れたブロックを実行します。
...容を返します。現在の行についてファイル名や行数を得るには
ARGF.class#filename と ARGF.class#lineno を使用します。
@param rs 行の区切りを文字列で指定します。nil を指定すると行区切りなし
とみなします。空文字列 "" を......フモード)。
@param limit 各行の最大の読み込みバイト数
例: ARGFの各ファイル名(最初に1回のみ)、行番号、内容を表示
ARGF.each_line do |line|
puts ARGF.filename if ARGF.lineno == 1
puts "#{ARGF.lineno}: #{line}"
end
@see IO#each, IO#each_line... -
Data
. define(*args) -> Class (6214.0) -
Data クラスに新しいサブクラスを作って、それを返します。
...ドが定義されています。
//emlist[例][ruby]{
Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)
p fred.name # => "Fred"
p fred.age # => 5
//}
メンバの値を書き換えることはできません。
//emlist[例][ruby]{
Dog = Data.define(:name, :age)
fred = Dog.new("Fred", 5)......ンマッチに利用できます。
//emlist[例][ruby]{
class HTTPFetcher
Response = Data.define(:body)
NotFound = Data.define
def get(url)
# ダミーの実装
if url == "http://example.com/"
Response.new(body: "Current time is #{Time.now}")
else
NotFound.new
e......end
end
def fetch(url)
fetcher = HTTPFetcher.new
case fetcher.get(url)
in HTTPFetcher::Response(body)
body
in HTTPFetcher::NotFound
:NotFound
end
end
p fetch("http://example.com/") # => "Current time is 2023-01-10 10:00:53 +0900"
p fetch("http://example.com/404") # => :NotFo... -
Gem
:: Version :: Requirement -> Class (6207.0) -
Gem::Requirement のエイリアスです。
...Gem::Requirement のエイリアスです。
//emlist[][ruby]{
p Gem::Version::Requirement == Gem::Requirement # => true
//}... -
ARGF
. class # each _ line(rs = $ / ) -> Enumerator (6118.0) -
ARGFの現在位置から 1 行ずつ文字列として読み込み、それを引数として与えら れたブロックを実行します。
...容を返します。現在の行についてファイル名や行数を得るには
ARGF.class#filename と ARGF.class#lineno を使用します。
@param rs 行の区切りを文字列で指定します。nil を指定すると行区切りなし
とみなします。空文字列 "" を......フモード)。
@param limit 各行の最大の読み込みバイト数
例: ARGFの各ファイル名(最初に1回のみ)、行番号、内容を表示
ARGF.each_line do |line|
puts ARGF.filename if ARGF.lineno == 1
puts "#{ARGF.lineno}: #{line}"
end
@see IO#each, IO#each_line... -
ARGF
. class # each _ line(rs = $ / , limit) -> Enumerator (6118.0) -
ARGFの現在位置から 1 行ずつ文字列として読み込み、それを引数として与えら れたブロックを実行します。
...容を返します。現在の行についてファイル名や行数を得るには
ARGF.class#filename と ARGF.class#lineno を使用します。
@param rs 行の区切りを文字列で指定します。nil を指定すると行区切りなし
とみなします。空文字列 "" を......フモード)。
@param limit 各行の最大の読み込みバイト数
例: ARGFの各ファイル名(最初に1回のみ)、行番号、内容を表示
ARGF.each_line do |line|
puts ARGF.filename if ARGF.lineno == 1
puts "#{ARGF.lineno}: #{line}"
end
@see IO#each, IO#each_line... -
Enumerable
# min {|a , b| . . . } -> object | nil (6112.0) -
ブロックの評価結果で各要素の大小判定を行い、最小の要素、もしくは最小の n 要素が昇順で入った配列を返します。 引数を指定しない形式では要素が存在しなければ nil を返します。 引数を指定する形式では、空の配列を返します。
...します。
引数を指定しない形式では要素が存在しなければ nil を返します。
引数を指定する形式では、空の配列を返します。
ブロックの値は、a > b のとき正、a == b のとき 0、
a < b のとき負の整数を、期待しています。
該....../emlist[例][ruby]{
class Person
attr_reader :name, :age
def initialize(name, age)
@name = name
@age = age
end
end
people = [
Person.new("sato", 55),
Person.new("sato", 33),
Person.new("sato", 11),
Person.new("suzuki", 55),
Person.new("suzuki", 33),
Person.new("suzuki", 1......ople.min { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => #<Person:0x007fd6f0824190 @name="tanaka", @age=11>
people.min(2) { |x, y| (x.age <=> y.age).nonzero? || y.name <=> x.name }
# => [#<Person:0x007fb5899ef4a8 @name="tanaka", @age=11>, #<Person:0x007fb5899ef728 @name="suzuki", @a...