{"id":15465488,"url":"https://github.com/hackvan/advanced-class-methods","last_synced_at":"2026-06-09T20:31:43.285Z","repository":{"id":145341434,"uuid":"140044906","full_name":"hackvan/advanced-class-methods","owner":"hackvan","description":null,"archived":false,"fork":false,"pushed_at":"2018-07-07T02:02:34.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T22:26:08.023Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hackvan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-07T02:02:23.000Z","updated_at":"2018-07-07T02:02:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"4b7fd813-95e8-4db7-ae16-5b7c4f8c79d3","html_url":"https://github.com/hackvan/advanced-class-methods","commit_stats":{"total_commits":1,"total_committers":1,"mean_commits":1.0,"dds":0.0,"last_synced_commit":"490dc3964624cdcf98d80b1cd10a825dd8655f58"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hackvan/advanced-class-methods","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackvan%2Fadvanced-class-methods","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackvan%2Fadvanced-class-methods/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackvan%2Fadvanced-class-methods/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackvan%2Fadvanced-class-methods/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackvan","download_url":"https://codeload.github.com/hackvan/advanced-class-methods/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackvan%2Fadvanced-class-methods/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34125332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T01:01:23.516Z","updated_at":"2026-06-09T20:31:43.266Z","avatar_url":"https://github.com/hackvan.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ruby Advanced Class Methods Lab\n\n## Objectives\n\n1. Build custom class constructors.\n2. Build class finders.\n3. Build class operators.\n\n## Instructions\n\nThis lab has provided you with a base `Song` class that provides the following definition:\n\n```ruby\nclass Song\n  attr_accessor :name, :artist_name\n  @@all = []\n\n  def self.all\n    @@all\n  end\n\n  def save\n    self.class.all \u003c\u003c self\n  end\n\nend\n\n```\n\nThe `Song` class provides a class variable `@@all` to store all instances for `Song` that are created through the instance method `Song#save`. Additionally, `Song` instances have basic properties of a name and an artist name.\n\nYou have to build class methods that interact on the class data of `@@all` and provide the rest of our program with a semantic API on the `Song` class with methods such as `Song.find_or_create_by_name(\"Blank Space\")`.\n\n### `Song.create`\n\nBuild a class constructor `Song.create` that initializes a song and saves it to the `@@all` class variable either literally or through the class method `Song.all`. This method should return the song instance that was initialized and saved.\n\nConsider:\n\n```ruby\nsong = Song.create\nSong.all.include?(song) #=\u003e true\n```\n\n### `Song.new_by_name`\n\nBuild a class constructor `Song.new_by_name` that takes in the string name of a song and returns a song instance with that name set as its name property. `Song.new_by_name` should return an instance of `Song` and not a simple string or anything else. Implement the following functionality:\n\n```ruby\nsong = Song.new_by_name(\"The Middle\")\n#=\u003e #\u003cSong @name=\"The Middle\"\u003e\nsong.name #=\u003e \"The Middle\"\n```\n\n### `Song.create_by_name`\n\nBuild a class constructor `Song.create_by_name` that takes in the string name of a song and returns a song instance with that name set as its name property and the song being saved into the `@@all` class variable.\n\nConsider:\n\n```ruby\nsong = Song.create_by_name(\"The Middle\")\n#=\u003e #\u003cSong:0x007fd2a2989ff0 @name=\"The Middle\"\u003e\nsong\n#=\u003e #\u003cSong:0x007fd2a2989ff0 @name=\"The Middle\"\u003e\nSong.all.include?(song)\n#=\u003e true\n```\n\n### `Song.find_by_name`\n\nBuild a class finder `Song.find_by_name` that accepts the string name of a song and returns the matching instance of the song with that name. Consider:\n\n```ruby\nthe_middle = Song.create_by_name(\"The Middle\")\n#=\u003e #\u003cSong @name=\"The Middle\"\u003e\n\nSong.find_by_name(\"The Middle\")\n#\u003cSong @name=\"The Middle\"\u003e\n```\n\n### `Song.find_or_create_by_name`\n\nIn order to prevent duplicate songs being created that actually represent the same song (based on the song name), we're going to build a `Song.find_or_create_by_name` class method. This method will accept a string name for a song and either return a matching song instance with that name or create a new song with the name and return the song instance.\n\nConsider:\n\n```ruby\nsong_1 = Song.find_or_create_by_name(\"Blank Space\")\nsong_2 = Song.find_or_create_by_name(\"Blank Space\")\n\n# song_1 and song_2 are conceptually the same song and should return the same song instance because of `.find_or_create_by_name.`\n\nsong_1 == song_2 #=\u003e true\n```\n\n### `Song.alphabetical`\n\nBuild a class method `Song.alphabetical` that returns all the songs in ascending (a-z) alphabetical order.\n\nUse [Array#sort_by](http://ruby-doc.org/core/Enumerable.html#method-i-sort_by).\n\n### `Song.new_from_filename`\n\nBuild a class constructor that accepts a filename in the format of \"\u003cArtist Name\u003e - \u003cSong Name\u003e.mp3\", for example \"Taylor Swift - Blank Space.mp3\".\n\nGiven `Song.new_from_filename(\"Taylor Swift - Blank Space.mp3\")`, the constructor should return a new `Song` instance with the song name set to Blank Space and the artist_name set to Taylor Swift. The filename input sent to `Song.new_from_filename` in the format of `Taylor Swift - Blank Space.mp3` must be parsed for the relevant components. Separate the artist name from the rest of the data based on the ` - ` delimiter. Don't forget that when you parse the song name, you have to remove the `'.mp3'` part of the string.\n\n```ruby\nsong = Song.new_from_filename(\"Taylor Swift - Blank Space.mp3\")\nsong.name #=\u003e \"Blank Space\"\nsong.artist_name #=\u003e \"Taylor Swift\"\n```\n\n### `Song.create_from_filename`\n\nBuild a class constructor that accepts a filename in the format of \"\u003cArtist Name\u003e - \u003cSong Name\u003e.mp3\", for example \"Taylor Swift - Blank Space.mp3\". The `Song.create_from_filename` class method should not only parse the filename correctly but should also save the Song instance that was created.\n\n### `Song.destroy_all`\n\nThe `Song.destroy_all` class method should reset the state of the `@@all` class variable to an empty array thereby deleting all previous song instances.\n\n\u003cp data-visibility='hidden'\u003eView \u003ca href='https://learn.co/lessons/ruby-advanced-class-methods-lab' title='Ruby Advanced Class Methods Lab'\u003eRuby Advanced Class Methods Lab\u003c/a\u003e on Learn.co and start learning to code for free.\u003c/p\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackvan%2Fadvanced-class-methods","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackvan%2Fadvanced-class-methods","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackvan%2Fadvanced-class-methods/lists"}