Class: Brauser::Value
- Inherits:
-
Object
- Object
- Brauser::Value
- Defined in:
- lib/brauser/value.rb
Overview
A defined entity, which supports comparison against a single or multiple values.
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
The wrapped value.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Check if an object is equal to another object or if it is contained in a list of objects.
-
#initialize(value) ⇒ Value
constructor
Creates a new value.
-
#method_missing(method, *args, &block) ⇒ Object
Delegates all the other values to the wrapped value.
Constructor Details
#initialize(value) ⇒ Value
Creates a new value
18 19 20 |
# File 'lib/brauser/value.rb', line 18 def initialize(value) @value = value end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Delegates all the other values to the wrapped value.
35 36 37 |
# File 'lib/brauser/value.rb', line 35 def method_missing(method, *args, &block) @value.send(method, *args, &block) end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns The wrapped value.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/brauser/value.rb', line 11 class Value attr_reader :value delegate :to_s, :inspect, to: :value # Creates a new value # # @param value [Object] The wrapped value. def initialize(value) @value = value end # Check if an object is equal to another object or if it is contained in a list of objects. # # @param other [Array|Object] The other object to match. # @return [Boolean] `true` if the current object is either equal or contained in the other object, `false` otherwise. def ==(other) other.is_a?(Array) ? other.include?(@value) : (@value == other) end # Delegates all the other values to the wrapped value. # # @param method [Symbol] The method to call. # @param args [Array] The arguments to pass to the method. # @param block [Proc] The block to pass to the method. def method_missing(method, *args, &block) @value.send(method, *args, &block) end end |
Instance Method Details
#==(other) ⇒ Boolean
Check if an object is equal to another object or if it is contained in a list of objects.
26 27 28 |
# File 'lib/brauser/value.rb', line 26 def ==(other) other.is_a?(Array) ? other.include?(@value) : (@value == other) end |