Skip to content

Instantly share code, notes, and snippets.

@billyyarosh
Last active December 9, 2021 05:16
Show Gist options
  • Save billyyarosh/65bfe0d8c6dc576a1d297c8d4e2b2348 to your computer and use it in GitHub Desktop.
Save billyyarosh/65bfe0d8c6dc576a1d297c8d4e2b2348 to your computer and use it in GitHub Desktop.
Song class
class Song
include ActiveModel::Model
include ActiveModel::Attributes
include ActiveModel::Serializers::JSON
attr_accessor :name, :artist, :genre, :id
validates_presence_of :name, :artist
def attributes=(hash)
hash.each do |key, value|
send("#{key}=", value)
end
end
def attributes
{
'name' => nil,
'artist' => nil,
'genre' => nil,
'id' => nil,
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment