dnwilson
dnwilson

Reputation: 147

Ruby: Is there a better way to write the following method?

Is there a better way to write the following method (if possible converting it into a single line?).

def create_array(opts)
  array = []
  opts.each{|key,value| array << value}
  array 
end

Upvotes: 1

Views: 66

Answers (1)

Oleksandr Holubenko
Oleksandr Holubenko

Reputation: 4440

If opts is hash so try it:

def create_array(opts)
    opts.values
end

Upvotes: 3

Related Questions