From: 7stud -- Date: 2011-05-11T06:07:10+09:00 Subject: Re: Starting Method/Class issues 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/.