Class: Puppet::Pops::Evaluator::CompareOperator
- Includes:
- Utils
- Defined in:
- lib/puppet/pops/evaluator/compare_operator.rb
Overview
Compares the puppet DSL way
Equality
All string vs. numeric equalities check for numeric equality first, then string equality Arrays are equal to arrays if they have the same length, and each element #equals Hashes are equal to hashes if they have the same size and keys and values #equals. All other objects are equal if they are ruby #== equal
Instance Method Summary collapse
-
#compare(a, b) ⇒ Object
Performs a comparison of a and b, and return > 0 if a is bigger, 0 if equal, and < 0 if b is bigger.
- #equals(a, b) ⇒ Object
-
#include?(a, b) ⇒ Boolean
Answers is b included in a.
-
#initialize ⇒ CompareOperator
constructor
A new instance of CompareOperator.
Methods included from Utils
find_adapter, find_closest_positioned, is_absolute?, is_numeric?, name_to_segments, relativize_name, to_n, to_n_with_radix
Constructor Details
#initialize ⇒ CompareOperator
Returns a new instance of CompareOperator.
12 13 14 15 16 17 |
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 12 def initialize @@equals_visitor ||= Puppet::Pops::Visitor.new(self, "equals", 1, 1) @@compare_visitor ||= Puppet::Pops::Visitor.new(self, "cmp", 1, 1) @@include_visitor ||= Puppet::Pops::Visitor.new(self, "include", 1, 1) @type_calculator = Puppet::Pops::Types::TypeCalculator.new() end |
Instance Method Details
#compare(a, b) ⇒ Object
Performs a comparison of a and b, and return > 0 if a is bigger, 0 if equal, and < 0 if b is bigger. Comparison of String vs. Numeric always compares using numeric.
25 26 27 |
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 25 def compare(a, b) @@compare_visitor.visit_this_1(self, a, b) end |
#equals(a, b) ⇒ Object
19 20 21 |
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 19 def equals (a, b) @@equals_visitor.visit_this_1(self, a, b) end |
#include?(a, b) ⇒ Boolean
Answers is b included in a
30 31 32 |
# File 'lib/puppet/pops/evaluator/compare_operator.rb', line 30 def include?(a, b) @@include_visitor.visit_this_1(self, a, b) end |