Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ruby will destructure objects that are not arrays, but respond to #to_ary,:b)
ss = [,2),,4)]
p{|a,b| "#{a} #{b}" }
# => ["#<struct S a=1, b=2> ", "#<struct S a=3, b=4> "]
class S ; def to_ary ; to_a ; end ; end
p{|a,b| "#{a} #{b}" }
# => ["1 2", "3 4"]

This comment has been minimized.

Copy link

@guizmaii guizmaii commented Dec 6, 2016

Great trick ! Thanks :) I talked about your trick here : ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.