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

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -