Ruby 1.9.2 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Rangeクラス
クラスの継承リスト: Range < Enumerable < Object < Kernel < BasicObject
範囲オブジェクトのクラス。範囲オブジェクトは範囲演算子 .. または ... によって生成されます。.. 演算子によって生成された範囲 オブジェクトは終端を含み、... 演算子によって生成された範囲オブジェ クトは終端を含みません。
for i in 1..5 # 処理 end
これは 1 から 5 までの範囲オブジェクトを生成して、それぞれの値に対して 繰り返すと言う意味です。
範囲演算子のオペランドは互いに <=> で比較できる必要があります。 さらに Range#each を実行するためには succ メソッ ドを実行できるものでなければいけません。
Ruby の Range クラスは immutable です。 つまり、オブジェクト自体を破壊的に変更することはできません。 ですので、一度生成された Range のオブジェクトの指し示す範囲は 決して変更することはできません。
range = 1..10 range.first #=> 1 range.first = 1 #=> NoMethodError
定義 | 説明 | |
---|---|---|
new(first, last, exclude_end = false) -> Range
|
first から last までの範囲オブジェクトを生成して返しま す。 |
定義 | 説明 | |
---|---|---|
self == other -> bool
|
指定された other が Range クラスのインスタンスであり、 始点と終点が == メソッドで比較して等しく、Range#exclude_end? が同じ場合に true を返します。そうでない場合に false を返します。 |
|
self === obj -> bool
|
obj が範囲内に含まれている時に真を返します。 |
|
begin -> object
|
最初の要素を返します。 |
|
cover?(obj) -> bool
|
obj が範囲内に含まれている時に真を返します。 |
|
each {|item| ... } -> self
|
範囲内の要素に対して繰り返します。 |
|
end -> object
|
終端を返します。範囲オブジェクトが終端を含むかどうかは関係ありませ ん。 |
|
eql?(other) -> bool
|
指定された other が Range クラスのインスタンスであり、 始点と終点が eql? メソッドで比較して等しく、Range#exclude_end? が同じ場合に true を返します。そうでない場合に false を返します。 |
|
equal?(other) -> bool
|
指定された other が self 自身である場合のみ真を返します。 これは Object クラスで定義されたデフォルトの動作で す。 |
|
exclude_end? -> bool
|
範囲オブジェクトが終端を含まないとき真を返します。 |
|
hash -> Integer
|
始点と終点のハッシュ値と Range#exclude_end? の値からハッシュ値を計算して整数として返します。 |
|
step(s = 1) {|item| ... } -> self
|
範囲内の要素を s おきに繰り返します。 |
!
!=
all?
any?
chunk
collect
collect_concat
count
cycle
detect
drop
drop_while
each_cons
each_entry
each_slice
each_with_index
each_with_object
entries
find_all
find_index
grep
group_by
inject
max
max_by
min
min_by
minmax
minmax_by
none?
one?
partition
reject
reverse_each
slice_before
sort
sort_by
take
take_while
to_set
zip
=~
__id__
__send__
_dump
class
clone
dclone
display
enum_for
extend
freeze
frozen?
initialize
initialize_copy
inspect
instance_eval
instance_exec
instance_of?
instance_variable_defined?
instance_variable_get
instance_variable_set
instance_variables
is_a?
marshal_dump
marshal_load
method
method_missing
methods
must_be
must_be_close_to
must_be_empty
must_be_instance_of
must_be_kind_of
must_be_nil
must_be_same_as
must_be_within_epsilon
must_equal
must_include
must_match
must_raise
must_respond_to
must_send
must_throw
nil?
pretty_inspect
pretty_print
pretty_print_cycle
pretty_print_inspect
pretty_print_instance_variables
private_methods
protected_methods
public_methods
remove_instance_variable
respond_to?
respond_to_missing?
singleton_class
singleton_method_added
singleton_method_removed
singleton_method_undefined
singleton_methods
taint
tainted?
tap
to_ary
to_hash
to_int
to_io
to_proc
to_regexp
to_s
to_str
to_yaml
to_yaml_properties
to_yaml_style
trust
untaint
untrust
untrusted?
wont_be
wont_be_close_to
wont_be_empty
wont_be_instance_of
wont_be_kind_of
wont_be_nil
wont_be_same_as
wont_be_within_epsilon
wont_equal
wont_include
wont_match
wont_respond_to
定義 | 説明 | ライブラリ |
---|---|---|
json_create(hash) -> Range
|
JSON のオブジェクトから Ruby のオブジェクトを生成して返します。 |
json/add/core |
to_json(*args) -> String
|
自身を JSON 形式の文字列に変換して返します。 |
json/add/core |