class Naturally::Segment
convert itself to an array.
a value which implements the {Comparable} interface which can
sorting. It’s an object representing
An entity which can be compared to other like elements for
def <=>(other)
def <=>(other) to_array <=> other.to_array end
def initialize(v)
def initialize(v) @val = v end
def to_array
- Example: Section 633a of the U.S. Age Discrimination in Employment Act -
Example: a college course code -
Example: a simple number -
Returns:
-
(Array)- a representation of myself in array form
def to_array # TODO: Refactor, probably via polymorphism if @val =~ /^(\p{Digit}+)(\p{Alpha}+)$/ [:int, $1.to_i, $2] elsif @val =~ /^(\p{Alpha}+)(\p{Digit}+)$/ [:str, $1, $2.to_i] elsif @val =~ /^\p{Digit}+$/ [:int, @val.to_i] else [:str, @val] end end