Class: DBus::Data::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dbus/data.rb

Overview

The base class for explicitly typed values.

A value is either Basic or a Container. Basic values are either Fixed-size or StringLike.

Direct Known Subclasses

Basic, Container

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Base

Child classes must validate value.



84
85
86
# File 'lib/dbus/data.rb', line 84

def initialize(value)
  @value = value
end

Instance Attribute Details

#value::Object (readonly)

Returns a valid value, plain-Ruby typed.

Returns:

  • (::Object)

    a valid value, plain-Ruby typed.

See Also:



63
64
65
# File 'lib/dbus/data.rb', line 63

def value
  @value
end

Class Method Details

.assert_type_matches_class(type) ⇒ Object

Parameters:

Raises:

  • (ArgumentError)


107
108
109
110
# File 'lib/dbus/data.rb', line 107

def self.assert_type_matches_class(type)
  raise ArgumentError, "Expecting #{type_code.inspect} for class #{self}, got #{type.sigtype.inspect}" \
    unless type.sigtype == type_code
end

.basic?Boolean

Returns:



# File 'lib/dbus/data.rb', line 55

.fixed?Boolean

Returns:



# File 'lib/dbus/data.rb', line 58

.from_typed(value, type: ) ⇒ Base

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Use DBus::Data.make_typed instead. Construct an instance of the specific subclass, with a type further specified in the type argument.

Parameters:

  • value (::Object)
  • type (Type) (defaults to: )

Returns:



# File 'lib/dbus/data.rb', line 74

.type_codeString

Returns a single-character string, for example “a” for arrays.

Returns:

  • (String)

    a single-character string, for example “a” for arrays



# File 'lib/dbus/data.rb', line 65

Instance Method Details

#==(other) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/dbus/data.rb', line 88

def ==(other)
  @value == if other.is_a?(Base)
              other.value
            else
              other
            end
end

#eql?(other) ⇒ Boolean

Hash key equality See ruby-doc.org/core-3.0.0/Object.html#method-i-eql-3F Stricter than #== (RSpec: eq), 1==1.0 but 1.eql(1.0)->false

Returns:



99
100
101
102
103
104
# File 'lib/dbus/data.rb', line 99

def eql?(other)
  return false unless other.class == self.class

  other.value.eql?(@value)
  # TODO: this should work, now check derived classes, exact_value
end

#typeType

This method is abstract.

Note that for Variants type==“v”, for the specific see Variant#member_type

Returns:

  • (Type)

    the exact type of this value



# File 'lib/dbus/data.rb', line 68