Class: ArrayFloe::Floe
- Inherits:
-
Object
- Object
- ArrayFloe::Floe
- Defined in:
- lib/array_floe/floe.rb
Overview
The class for the “floe” object constructed by Array#each_with_floe and Array#each_with_index_floe
Instance Method Summary collapse
-
#even? ⇒ Boolean
Returns true for even-numbered elements.
-
#first? ⇒ Boolean
Returns true for the first element.
-
#initialize(i, size) ⇒ Floe
constructor
:nodoc:.
-
#last? ⇒ Boolean
Returns true for the last element.
-
#odd? ⇒ Boolean
Returns true for odd-numbered elements.
-
#to_s ⇒ Object
Returns a space-separated list of “first”, “last”, “odd”, and “even” as appropriate for the current element.
Constructor Details
#initialize(i, size) ⇒ Floe
:nodoc:
6 7 8 9 10 |
# File 'lib/array_floe/floe.rb', line 6 def initialize(i, size) # :nodoc: @first = i == 0 @last = i == size -1 @odd = i.odd? end |
Instance Method Details
#even? ⇒ Boolean
Returns true for even-numbered elements
28 29 30 |
# File 'lib/array_floe/floe.rb', line 28 def even? !@odd end |
#first? ⇒ Boolean
Returns true for the first element
13 14 15 |
# File 'lib/array_floe/floe.rb', line 13 def first? @first end |
#last? ⇒ Boolean
Returns true for the last element
18 19 20 |
# File 'lib/array_floe/floe.rb', line 18 def last? @last end |
#odd? ⇒ Boolean
Returns true for odd-numbered elements
23 24 25 |
# File 'lib/array_floe/floe.rb', line 23 def odd? @odd end |
#to_s ⇒ Object
Returns a space-separated list of “first”, “last”, “odd”, and “even” as appropriate for the current element.
34 35 36 |
# File 'lib/array_floe/floe.rb', line 34 def to_s @str ||= [@first && "first", @last && "last", @odd ? "odd" : "even"].select{|x| x}.join(' ') end |