Module: Discordrb::Events

Included in:
Bot
Defined in:
lib/discordrb/events/typing.rb,
lib/discordrb/events/generic.rb,
lib/discordrb/events/message.rb,
lib/discordrb/events/lifetime.rb,
lib/discordrb/events/presence.rb,
lib/discordrb/events/channel-create.rb,
lib/discordrb/events/channel-delete.rb,
lib/discordrb/events/channel-update.rb,
lib/discordrb/events/guild-role-create.rb,
lib/discordrb/events/guild-role-delete.rb,
lib/discordrb/events/guild-role-update.rb,
lib/discordrb/events/voice-state-update.rb,
lib/discordrb/events/guild-member-update.rb

Defined Under Namespace

Classes: ChannelCreateEvent, ChannelCreateEventHandler, ChannelDeleteEvent, ChannelDeleteEventHandler, ChannelUpdateEvent, ChannelUpdateEventHandler, DisconnectEvent, DisconnectEventHandler, EventHandler, GuildMemberUpdateEvent, GuildMemberUpdateHandler, GuildRoleCreateEvent, GuildRoleCreateEventHandler, GuildRoleDeleteEvent, GuildRoleDeleteEventHandler, GuildRoleUpdateEvent, GuildRoleUpdateEventHandler, MentionEvent, MentionEventHandler, MessageEvent, MessageEventHandler, Negated, PresenceEvent, PresenceEventHandler, ReadyEvent, ReadyEventHandler, TrueEventHandler, TypingEvent, TypingEventHandler, VoiceStateUpdateEvent, VoiceStateUpdateEventHandler

Class Method Summary collapse

Class Method Details

.matches_all(attributes, to_check, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/discordrb/events/generic.rb', line 9

def self.matches_all(attributes, to_check, &block)
  # "Zeroth" case: attributes is nil
  return true unless attributes

  # First case: there's a single negated attribute
  if attributes.is_a? Negated
    # The contained object might also be an array, so recursively call matches_all (and negate the result)
    return !matches_all(attributes.object, to_check, &block)
  end

  # Second case: there's a single, not-negated attribute
  unless attributes.is_a? Array
    return yield(attributes, to_check)
  end

  # Third case: it's an array of attributes
  attributes.reduce(false) do |result, element|
    result || yield(element, to_check)
  end
end