/user.rb Secret
Created
October 7, 2014 15:21
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'set' | |
class User | |
extend Enumerable | |
def self.all | |
@all ||= Set.new | |
end | |
def self.create(attrs = {}) | |
all << new(attrs) | |
end | |
def self.each(&block) | |
all.each(&block) | |
end | |
attr_reader :attributes | |
def initialize(attributes = {}) | |
@attributes = attributes | |
end | |
def method_missing(m, *args) | |
attributes[m] || super | |
end | |
end | |
User.create name: "Lee" | |
p User.find { |u| u.name == "Lee" } #<User:0x007ff7539b4518 @attributes={:name=>"Lee"}> | |
p User.find { |u| u.name == "Bob" } #=> nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment