Method: Discordrb::Cache#ensure_user

Defined in:
lib/discordrb/cache.rb

#ensure_user(data) ⇒ User

Ensures a given user object is cached and if not, cache it from the given data hash.

Parameters:

  • data (Hash)

    A data hash representing a user.

Returns:

  • (User)

    the user represented by the data hash.



139
140
141
142
143
144
145
# File 'lib/discordrb/cache.rb', line 139

def ensure_user(data)
  if @users.include?(data['id'].to_i)
    @users[data['id'].to_i]
  else
    @users[data['id'].to_i] = User.new(data, self)
  end
end