On Nov 23, 3:05 pm, Julie May <[email protected]> wrote:
> From your comment it looks like I may need to understand why I would need
> to assign values  return is already part of the text so my assumption is
> that I just have to .to_sym it.  However, if I have to assign and deliver
> something that would change quite a bit.

Calling .to_sym on a string returns a NEW symbol. It does exactly
nothing to the string you called it on.

>
> Clarification.
>
> The desired resulting line is:
>  ele.send_keys('Student One', :return, 'Student Two', :return)
> Basically "'Student One', :return, 'Student Two', :return" is parsed to
> result in itself except with the symbols understood as symbol type.
>
> In the original:
> x[0] == 'Student One'
> ', ' is added since it is not the last element
> x[1] == 'return' output as x[1].to_sym which adds the : itself.
> ', ' is added since it is not the last element
>
> Pattern repeats.

No. You don't need to put commas in when you're splatting an array. An
example:

def foo(arg1, arg2, arg3)
  puts "arg1 is #{arg1.inspect}"
  puts "arg2 is #{arg2.inspect}"
  puts "arg3 is #{arg3.inspect}"
end

a = [1,2,3]

Then calling:

foo(*a)

will result in:
arg1 is 1
arg2 is 2
arg3 is 3


> Mat, your idea has made the :return do what it is supposed to but now I'm
> unable to get the text to output.  All that is coming out is the symbols
> even though puts on the text line shows it should be displaying in the
> following:
> (I added .to_s even though I shouldn't have to just to be sure the type
> hadn't changed.)
>
>      items = text.split(/,\s?/)
>       ele.send_keys(*items.map {|x|
>       case x
>         when /^.*'.*/ then $1.to_s+', '

$1 is not being set here - it's used to capture the first set of
parentheses in a regular expression. Your regex is missing them.

>         when /^:(.*)$/ then $1.to_sym    # ":return"       => :return

>         else $1.to_s                                   #return unknowns as is 
> (nothing should hit this)

Again, $1 will not be set here. x.to_s would be a suitable default.

> I also am unsure how the case structure can detect if the element is 'last'
> so that it doesn't add the comma on the last element.

No commas needed. :)

I highly recommend you check out Programming Ruby (aka "The Pickaxe")
- or at least the first edition of it, available free here:

http://www.ruby-doc.org/docs/ProgrammingRuby/

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to