struct Range(B, E)
- Range(B, E)
- Struct
- Value
- Object
Overview
A Range represents an interval: a set of values with a beginning and an end.
Ranges may be constructed using the usual new method or with literals:
x..y # an inclusive range, in mathematics: [x, y]
x...y # an exclusive range, in mathematics: [x, y)
(x..) # an endless range, in mathematics: >= x
..y # a beginless inclusive range, in mathematics: <= y
...y # a beginless exclusive range, in mathematics: < y
See Range literals in the language reference.
An easy way to remember which one is inclusive and which one is exclusive it to think of the extra dot as if it pushes y further away, thus leaving it outside of the range.
Ranges typically involve integers, but can be created using arbitrary objects
as long as they define succ (or pred for reverse_each), to get the
next element in the range, and < and ==, to know when the range reached the end:
# Represents a string of 'x's.
struct Xs
include Comparable(Xs)
getter size
def initialize(@size : Int32)
end
def succ
Xs.new(@size + 1)
end
def <=>(other)
@size <=> other.size
end
def inspect(io)
@size.times { io << 'x' }
end
def to_s(io)
io << @size << ' '
inspect(io)
end
end
An example of using Xs to construct a range:
r = Xs.new(3)..Xs.new(6)
r.to_s # => "xxx..xxxxxx"
r.to_a # => [Xs.new(3), Xs.new(4), Xs.new(5), Xs.new(6)]
r.includes?(Xs.new(5)) # => true
Included Modules
- Enumerable(B)
- Iterable(B)
Defined in:
chem/core_ext/range.crInstance Method Summary
-
#===(atom : Chem::Atom) : Bool
Case equality.
-
#===(chain : Chem::Chain) : Bool
Case equality.
-
#===(residue : Chem::Residue) : Bool
Case equality.
- #clamp(min, max) : Range
- #clamp(range : Range) : Range
Instance methods inherited from module Enumerable(B)
===(atom : Chem::Atom) : Bool===(chain : Chem::Chain) : Bool
===(residue : Chem::Residue) : Bool ===, average(weights : Indexable(Number))
average(weights : Indexable(Number), & : T -> _) average, find(pattern, if_none default = nil) find, find!(pattern) find!, mean
mean(& : T -> _) mean, to_dcd(io : IO, title : String | Nil = nil) : Nil
to_dcd(title : String | Nil = nil) : String
to_dcd(path : Path | String, title : String | Nil = nil) : Nil to_dcd, to_mol2(io : IO) : Nil
to_mol2(path : Path | String) : Nil
to_mol2 : String to_mol2, to_pdb(io : IO, conect conect_options : PDB::ConectOptions = PDB::ConectOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : Nil
to_pdb(conect conect_options : PDB::ConectOptions = PDB::ConectOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : String
to_pdb(path : Path | String, conect conect_options : PDB::ConectOptions = PDB::ConectOptions.flags(Het, Disulfide), renumber : Bool = true, ter_on_fragment : Bool = false) : Nil to_pdb, to_sdf(io : IO, variant : Mol::Variant = :v2000) : Nil
to_sdf(path : Path | String, variant : Mol::Variant = :v2000) : Nil
to_sdf(variant : Mol::Variant = :v2000) : String to_sdf, to_xyz(io : IO, extended : Bool = false, fields : Array(String) = [] of String) : Nil
to_xyz(extended : Bool = false, fields : Array(String) = [] of String) : String
to_xyz(path : Path | String, extended : Bool = false, fields : Array(String) = [] of String) : Nil to_xyz