Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #4204

Re: Starting Method/Class issues

From 7stud -- <bbxx789_05ss@yahoo.com>
Newsgroups comp.lang.ruby
Subject Re: Starting Method/Class issues
Date 2011-05-10 16:07 -0500
Organization Service de news de lacave.net
Message-ID <71429885376e6338580943ad50c8eb2e@ruby-forum.com> (permalink)
References <db27adb124f75fd3cd3e99b520e711c7@ruby-forum.com>

Show all headers | View raw


TJ Wilkes wrote in post #997808:
> Hi I've been learning Ruby to help with scripting some tests, but the
> books I have are only using mathematical method/class creations and my
> attempts to make my own methods are failing.  Looking for some help with
> the creation of two time savers.
>
> Note: Using ruby 1.8.7 and Watir-webdriver as well as IE 9.
>
> I'm trying to set up some page validation scripts but every attempt has
> failed, these run prefectly fine in the program if I repeat them and
> fill in linkX and PagetextX with specfics each time
>

How about an example of that?

Your question is very hard to decipher.  It appears that you have some 
code with a string in it, e.g. linkX, and you don't understand what a 
variable is or how to use one in a string.  So here are some examples:


arr = [10, 30, 20]

arr.each do |num|
  puts "The numbers is: #{num}"
end

--output:--
The numbers is: 10
The numbers is: 30
The numbers is: 20



Next, instead of using a variable inside a string, you can also call a 
function:

def verify(x)
  if x > 15
    'valid'
  else
    'invalid'
  end
end


arr = [10, 30, 20]

arr.each do |num|
  puts "The page is: #{verify(num)}"
end

--output:--
The page is: invalid
The page is: valid
The page is: valid


But sometimes trying to cram to0 much code in a string can be confusing, 
so you could do something like this as well:

def verify(x)
  if x > 15
    true
  else
    false
  end
end


arr = [10, 30, 20]

arr.each do |num|
  print 'The page is: '

  if verify(num)
    puts 'valid'
  else
    puts 'invalid'
  end
end


--output:--
The page is: invalid
The page is: valid
The page is: valid

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Starting Method/Class issues TJ Wilkes <tjwilkes@live.com> - 2011-05-10 12:32 -0500
  Re: Starting Method/Class issues Robert Klemme <shortcutter@googlemail.com> - 2011-05-10 22:18 +0200
  Re: Starting Method/Class issues 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-10 16:07 -0500
    Re: Starting Method/Class issues TJ Wilkes <tjwilkes@live.com> - 2011-05-10 16:34 -0500
      Re: Starting Method/Class issues 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-10 19:26 -0500
    Re: Starting Method/Class issues Brian Candler <b.candler@pobox.com> - 2011-05-11 03:39 -0500
  Re: Starting Method/Class issues TJ Wilkes <tjwilkes@live.com> - 2011-05-11 14:28 -0500
    Re: Starting Method/Class issues 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-11 14:56 -0500
  Re: Starting Method/Class issues TJ Wilkes <tjwilkes@live.com> - 2011-05-11 16:04 -0500
    Re: Starting Method/Class issues 7stud -- <bbxx789_05ss@yahoo.com> - 2011-05-11 17:39 -0500

csiph-web