Created
September 5, 2011 05:51
-
-
Save ohta-rh/1194188 to your computer and use it in GitHub Desktop.
defile_method sample
This file contains hidden or 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
| #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