Class: ValueSemantics::RangeOf

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subvalidator) ⇒ RangeOf



5
6
7
# File 'lib/value_semantics/range_of.rb', line 5

def initialize(subvalidator)
  @subvalidator = subvalidator
end

Instance Attribute Details

#subvalidatorObject (readonly)

Returns the value of attribute subvalidator.



3
4
5
# File 'lib/value_semantics/range_of.rb', line 3

def subvalidator
  @subvalidator
end

Instance Method Details

#===(obj) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/value_semantics/range_of.rb', line 9

def ===(obj)
  return false unless Range === obj

  # begin or end can be nil, if the range is beginless or endless
  [obj.begin, obj.end].compact.all? do |element|
    subvalidator === element
  end
end