Is there a way to apply multiple method by one liner in ruby? -
there array this:
a = [1,2,3,4]
i want homecoming values of size
, sum
this.
size = a.size sum = a.sum
is there way both values one-liner this?
size, sum = a.some_method(&:size, &:sum)
in ruby, can multiple assignments in 1 line:
size, sum = a.size, a.sum
it doesn't create more readable, though.
ruby-on-rails ruby
No comments:
Post a Comment