Class: SortedArrayBinary::ComparisonState

Inherits:
Object
  • Object
show all
Defined in:
lib/sorted_array_binary.rb

Overview

{{{2 ComparisonState

Instance Method Summary collapse

Constructor Details

#initialize(state) ⇒ ComparisonState

:nodoc:

Raises:

  • (ArgumentError)


19
20
21
22
23
24
# File 'lib/sorted_array_binary.rb', line 19

def initialize state
  raise ArgumentError, "invalid state: #{state.inspect}" \
  unless state && state >= -1 && state <= 1

  @state = state
end

Instance Method Details

#equal?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/sorted_array_binary.rb', line 26

def equal?
  @state == 0
end

#greater?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/sorted_array_binary.rb', line 30

def greater?
  @state == 1
end

#less?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/sorted_array_binary.rb', line 34

def less?
  @state == -1
end