Class: JSONAPIonify::CharacterRange
- Inherits:
-
Object
- Object
- JSONAPIonify::CharacterRange
- Includes:
- Enumerable
- Defined in:
- lib/jsonapionify/character_range.rb
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(start_char, end_char) ⇒ CharacterRange
constructor
A new instance of CharacterRange.
- #to_a ⇒ Object
Constructor Details
#initialize(start_char, end_char) ⇒ CharacterRange
Returns a new instance of CharacterRange.
11 12 13 14 15 16 17 |
# File 'lib/jsonapionify/character_range.rb', line 11 def initialize(start_char, end_char) if [start_char, end_char].any? { |c| c.length > 1 } raise ArgumentError, 'must be single characters' end @start_char = start_char @end_char = end_char end |
Class Method Details
.[](*args) ⇒ Object
6 7 8 |
# File 'lib/jsonapionify/character_range.rb', line 6 def [](*args) new(*args) end |
Instance Method Details
#each ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jsonapionify/character_range.rb', line 19 def each range.each do |ord| begin char = ord.chr(Encoding::UTF_8) yield char rescue RangeError next end end end |
#to_a ⇒ Object
30 31 32 |
# File 'lib/jsonapionify/character_range.rb', line 30 def to_a each.to_a end |