Skip to content

Instantly share code, notes, and snippets.

@kamipo
Created December 31, 2018 12:55
Show Gist options
  • Save kamipo/a2c83f9a91e8c368a1014f86cd01af00 to your computer and use it in GitHub Desktop.
Save kamipo/a2c83f9a91e8c368a1014f86cd01af00 to your computer and use it in GitHub Desktop.
def foo(x)
a = x.flat_map(&:bar)
(a + [1]).flatten
end
def foo2(x)
a = x.flat_map(&:bar)
a + [1]
end
X = Struct.new(:bar)
x = [X.new([[:x]])]
p foo(x) # => [:x, 1]
p foo2(x) # => [[:x], 1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment