Is there a succinct way in ruby to return the array itself when the array is not empty -
basically i'd check array , set variable if not empty @ same time: in same way can assign variable while checking boolean, i'd able array. e.g :
bar = "hello world" if foo = bar.is_a?(string) puts foo end => "hello world" bar = [1,2,3] if foo = !bar.empty? puts foo end => 1 2 3
how about:
my_array = array.empty? ? do_something(array) : array
Comments
Post a Comment