Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module AwesomeResource
def initialize(attributes = {})
attributes.each do |key, val|
reader = key
writer = "#{key}="
unless respond_to?(reader)
self.class.send(:attr_reader, key)
end
unless respond_to?(writer)
self.class.send(:attr_writer, key)
end
send(writer, val)
end
end
end
describe AwesomeResource do
it "creates readers and writers for any attributes passed in during initialization" do
article_class = Class.new do
include AwesomeResource
end
article = article_class.new("title" => "Fun")
article.title.should == "Fun"
article.title = 'Fun Times!'
article.title.should == 'Fun Times!'
expect { article.unknown_attribute }.to raise_exception
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.