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
#==, #fetch_reference, from_ruby, #hash, #object_key, #truthy?, #type_name, #undefined?
Constructor Details
#initialize(elements) ⇒ SetValue
Create a set value.
353 354 355 356 357 |
# File 'lib/ruby/rego/value.rb', line 353 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.
363 364 365 |
# File 'lib/ruby/rego/value.rb', line 363 def include?(value) @elements.include?(Value.from_ruby(value)) end |
#to_ruby ⇒ Set<Object>
Convert the set back to Ruby.
370 371 372 |
# File 'lib/ruby/rego/value.rb', line 370 def to_ruby Set.new(@elements.map(&:to_ruby)) end |