class Content
Wraps the content object of a Matrix event, providing typed access to schema-defined properties via method_missing.
Common fields like msgtype, body, and membership have dedicated
accessors for convenience. Any other field defined in the event's schema
(or present in the raw hash) is accessible as a method call:
content.msgtype # => "m.text" content.body # => "hello" content.membership # => "join" content.avatar_url # => "mxc://example.org/abc" content["custom"] # => direct hash access for non-standard fields
Definitions
def [](key)
Direct hash access for any content field.
Implementation
def [](key)
@data[key.to_s]
end
def to_h
Returns the raw content hash.
Implementation
def to_h
@data
end
def method_missing(name, *args)
Dynamic access to any content field present in the raw data.
Implementation
def method_missing(name, *args)
key = name.to_s
if @data.key?(key)
@data[key]
else
nil
end
end