excluded = "a", " an", " the", " at", " in", " on ", "since"
temp = excluded.split(",").each {|val| val = val.strip}
But I am getting the same array. Its not striping. I need to do this in single line
i need the output in temp like [“a”, “an”, “the”, “at”, “in”, “on”, “since”]
As you can see from the docs
Array#eachreturns the original receiver (ary.each {|item| block } → ary). What you want — as others have already pointed out — is Array#map.Also your current code should raise a
NoMethodErrorbecause of calling split on an array. Assuming thatexcludedis a string, the following will work:Instead of using
stripyou can also just change what you split on: