Last active
December 8, 2016 14:50
-
-
Save iamvery/058403c84fb22da1bbe10c35726448f6 to your computer and use it in GitHub Desktop.
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
class Object | |
def extract(*messages) | |
messages.map(&method(:public_send)) | |
end | |
end | |
RSpec.describe Object do | |
Foo = Struct.new(:bar, :baz) | |
describe "#extract" do | |
it "extracts each message from object" do | |
bar, baz = Foo.new("lol", "wat").extract(:bar, :baz) | |
expect(bar).to eq("lol") | |
expect(baz).to eq("wat") | |
end | |
end | |
describe "alternatives" do | |
it "extracts each message from object" do | |
foo = Foo.new("lol", "wat") | |
bar, baz = [:bar, :baz].map(&foo.method(:public_send)) | |
expect(bar).to eq("lol") | |
expect(baz).to eq("wat") | |
end | |
it "is just some messages" do | |
foo = Foo.new("lol", "wat") | |
bar, baz = foo.bar, foo.baz | |
expect(bar).to eq("lol") | |
expect(baz).to eq("wat") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment