From: Ammar Ali Date: 2010-06-15T07:59:20+09:00 Subject: Re: split doesn't work Sora's suggestion works, but doesn't explain what is going on. The reason is that the variable (@def) is a string the first time around, but after the first split it becomes an array because that's what split returns. You can convert it back to a string after the shift with to_s or join, like so: definition = definition.to_s or definition = definition.join(' ') Adding a '=' essential calls to_s on the array. By the way, def is a reserved keyword, I would avoid using it as a variable name, especially since there are better choices. HTH, Ammar On Tue, Jun 15, 2010 at 1:45 AM, Sora Harakami wrote: > On Tue, Jun 15, 2010 at 7:19 AM, Jennifer Lee wrote: >> I have code: >> >> <% @terms.each do |term| %>> >> >>  <%regex = Regexp.new(/#{term}/)%> >>  <%matchdata = regex.match(@def_str)%> >>  <%if matchdata%> >> >>    <%  @def = @def.split(/#{term}/) %> >>    <%  @def.shift %> >> >>  <%end%> >> <%end%> > > Hi, > >>    <%  @def.shift %> > This line is run only and doesn't output value. > > So change this line to: <%= @def.shift %> > to solve this problem. > > Thanks. > > -- > Sora Harakami - @sora_h > Blog: http://codnote.net/ > Detail: http://sorah.cosmio.net/ > >