{"id":15405619,"url":"https://github.com/krisleech/persistent-hash","last_synced_at":"2025-03-24T21:41:22.947Z","repository":{"id":805295,"uuid":"509574","full_name":"krisleech/Persistent-Hash","owner":"krisleech","description":"Simple example used to teach several Ruby coding techniques","archived":false,"fork":false,"pushed_at":"2010-02-09T14:39:57.000Z","size":76,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T04:44:46.674Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/krisleech.png","metadata":{"files":{"readme":"README","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}},"created_at":"2010-02-09T14:24:22.000Z","updated_at":"2013-10-02T02:11:38.000Z","dependencies_parsed_at":"2022-07-05T16:02:20.594Z","dependency_job_id":null,"html_url":"https://github.com/krisleech/Persistent-Hash","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2FPersistent-Hash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2FPersistent-Hash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2FPersistent-Hash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krisleech%2FPersistent-Hash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krisleech","download_url":"https://codeload.github.com/krisleech/Persistent-Hash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245359248,"owners_count":20602322,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-01T16:17:32.538Z","updated_at":"2025-03-24T21:41:22.912Z","avatar_url":"https://github.com/krisleech.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"A Persistent Hash\n\nA Hash is a very powerful class in Ruby and can be quickly turned in to a rudimentary database with full CRUD and search capabilities. \n\nThis simple class example demonstrates a number of Ruby techniques including:\n\n* read/write files\n* YAML\n* inheritance\n* writing classes\n* super\n* KISS \n* CoC (Convention Over Configuration)\n* blocks\n* method chaining\n\n== Example Usage ==\n\nrequire 'phash'\n\nclass Products \u003c Database\nend\n\n# Create a new database, or load an existing database\nproducts = Products.new\n\n# FIND A RECORD\n\nproducts[:blue_widget]\n# =\u003e Hash\n\n# ITERATE THROUGH ALL RECORDS\n\nproducts.each do | name, attributes |\n\tputs name\n\tputs attributes.inspect\nend\n\n# DELETE A RECORD\n\nproducts.delete(:green_widget)\n\n# CREATE/UPDATE A RECORD\n\nproducts[:red_widget] = { :name =\u003e 'Red Widget', :size =\u003e 'large', :weight =\u003e 50, :color =\u003e 'red' }\nproducts.save\n\n# QUERY THE DATABASE\n\nproducts.select { |p| p[:weight] \u003e 60 }.each do | product |\n  product[:size] = 'large'\nend\n\n# Note the key can be anything so long as it is unique, for example a SKU code.\n\n== This is used as a teaching example in the Impartica IT Training RubyOnRails Course ==","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrisleech%2Fpersistent-hash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrisleech%2Fpersistent-hash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrisleech%2Fpersistent-hash/lists"}