Skip to content

Instantly share code, notes, and snippets.

@ohta-rh
Created September 5, 2011 05:51
Show Gist options
  • Select an option

  • Save ohta-rh/1194188 to your computer and use it in GitHub Desktop.

Select an option

Save ohta-rh/1194188 to your computer and use it in GitHub Desktop.
defile_method sample
#attrs = { foo: "foo", bar: "bar", baz: "baz" ,,,,}
class DefineMethodSample
def initialize(attrs)
attrs.symbolize_keys!
attrs.each do |k, v|
self.class.send(:define_method, k) { return(v) }
end
end
end
#spec
describe DefineMethodSample do
describe "#initialize and define_method" do
subject { ::DefineMethodSample.new({ foo: "foo" }) }
specify { expect{ subject.foo }.to_not raise_error(NoMethodError) }
it { subject.foo.should be_eql("foo") }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment