Range

Range

ri

 ----------------------------------------------------------- Class: Range
      A  Range  represents an interval---a set of values with a start and
      an end. Ranges may be constructed using the _s_ .. _e_ and
      _s_ ... _e_ literals, or with  Range::new . Ranges constructed
      using  ..  run from the start to the end inclusively. Those created
      using  ...  exclude the end value. When used as an iterator, ranges
      return each value in the sequence.
 
         (-1..-5).to_a      #=> []
         (-5..-1).to_a      #=> [-5, -4, -3, -2, -1]
         ('a'..'e').to_a    #=> ["a", "b", "c", "d", "e"]
         ('a'...'e').to_a   #=> ["a", "b", "c", "d"]
 
      Ranges can be constructed using objects of any type, as long as the
      objects can be compared using their  <=>  operator and they support
      the  succ  method to return the next object in sequence.
 
         class Xs                # represent a string of 'x's
           include Comparable
           attr :length
           def initialize(n)
             @length = n
           end
           def succ
             Xs.new(@length   1)
           end
           def <=>(other)
             @length <=> other.length
           end
           def to_s
             sprintf "%2d #{inspect}", @length
           end
           def inspect
             'x' * @length
           end
         end
      
         r = Xs.new(3)..Xs.new(6)   #=> xxx..xxxxxx
         r.to_a                     #=> [xxx, xxxx, xxxxx, xxxxxx]
         r.member?(Xs.new(5))       #=> true
 
      In the previous code example, class  Xs  includes the  Comparable 
      module. This is because  Enumerable#member?  checks for equality
      using  == . Including  Comparable  ensures that the  ==  method is
      defined in terms of the  <=>  method implemented in  Xs .
 
 ------------------------------------------------------------------------
 
 
 Includes:
 ---------
      Enumerable(all?, any?, collect, detect, each_cons, each_slice,
      each_with_index, entries, enum_cons, enum_slice, enum_with_index,
      find, find_all, grep, include?, inject, map, max, member?, min,
      partition, reject, select, sort, sort_by, to_a, to_set, zip)
 
 
 Class methods:
 --------------
      new
 
 
 Instance methods:
 -----------------
      ==, ===, begin, each, end, eql?, exclude_end?, first, hash,
      include?, inspect, last, member?, step, to_s

refe

 ==== Range ====
 範囲オブジェクトクラス。範囲オブジェクトは範囲演算子 .. または 
 ... によって生成されます。.. 演算子によって生成された範囲
 オブジェクトは終端を含み、... 演算子によって生成された範囲オブジェ
 クトは終端を含みません。
 
 例:
 
   for i in 1..5
      ...
   end
 
 これは 1 から 5 までの範囲オブジェクトを生成して、それぞれの値に対して
 繰り返すと言う意味です。
 
 範囲演算子オペランドは互いに <=> で比較できる必要があります。
 さらに Range#each [Range/each] を実行するためには succ メソッ
 ドを実行できるものでなければいけません。
 ---- Singleton methods ----
 new
 ---- Instance methods ----
 === begin each end exclude_end? first last length size step
 ---- Singleton methods (inherited) ----
 ---- Instance methods (inherited) ----
 == =~ __id__ __send__ _dump _load all? any? class clone
 collect detect display dup each_with_index entries eql?
 equal? extend find find_all freeze frozen? grep hash id
 include? initialize initialize_copy inject inspect
 instance_eval instance_of? instance_variable_get
 instance_variable_set instance_variables is_a? kind_of? map
 marshal_dump marshal_load max member? method method_missing
 methods min nil? object_id partition pretty_print
 pretty_print_cycle pretty_print_instance_variables
 private_methods protected_methods public_methods reject
 remove_instance_variable respond_to? select send
 singleton_method_added singleton_method_removed
 singleton_method_undefined singleton_methods sort sort_by
 taint tainted? to_a to_ary to_hash to_int to_s to_str type
 untaint zip