Class: Ruby::Rego::SetValue
Overview
Represents a set value.
Constant Summary collapse
- TYPE_NAME =
"set"
Instance Attribute Summary
Attributes inherited from Value
Instance Method Summary collapse
-
#include?(value) ⇒ Boolean
Check whether the set includes a value.
-
#initialize(elements) ⇒ SetValue
constructor
Create a set value.
-
#to_ruby ⇒ Set<Object>
Convert the set back to Ruby.
Methods inherited from Value
#==, #canonical, canonicalize, canonicalize_each, canonicalize_float, #fetch_reference, from_ruby, #hash, #object_key, #truthy?, #type_name, #undefined?
Constructor Details
#initialize(elements) ⇒ SetValue
Create a set value.
443 444 445 446 447 |
# File 'lib/ruby/rego/value.rb', line 443 def initialize(elements) collection = elements.is_a?(Set) ? elements.to_a : Array(elements) @elements = Set.new(collection.map { |element| Value.from_ruby(element) }) super(@elements) end |
Instance Method Details
#include?(value) ⇒ Boolean
Check whether the set includes a value.
453 454 455 |
# File 'lib/ruby/rego/value.rb', line 453 def include?(value) @elements.include?(Value.from_ruby(value)) end |
#to_ruby ⇒ Set<Object>
Convert the set back to Ruby.
460 461 462 |
# File 'lib/ruby/rego/value.rb', line 460 def to_ruby Set.new(@elements.map(&:to_ruby)) end |