Skip to content

Instantly share code, notes, and snippets.

@iamvery
Last active December 8, 2016 14:50
Show Gist options
  • Save iamvery/058403c84fb22da1bbe10c35726448f6 to your computer and use it in GitHub Desktop.
Save iamvery/058403c84fb22da1bbe10c35726448f6 to your computer and use it in GitHub Desktop.
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