Although I've played around with both Bash and Python, I keep coming back to Ruby. This is partly because that's what the developers where I work use (I'm in QA and customer service and not a developer). In general, I find Ruby to be pretty user friendly and accessible for a n00b like me.
My basic guide is Chris Pine's "Learn to Program." A friend gave me the book, but a shorter version is also available online. In attempting to do the work suggested in the book I came up with the two items below.
The first is a simple program that asks first, middle and last names and then puts them together at the end. Check out how I did the spacing on the last line. That can't be the best way to do that, can it?
puts 'What\'s your first name?'
firstname = gets.chomp
puts firstname + '? Nice! So how about your middle name?'
secondname = gets.chomp
puts 'That\'s a good middle name. I guess you know what I want to know now! What\'s your last name?'
lastname = gets.chomp
puts 'Great! So your full name is ' + firstname + ' ' + secondname + ' ' + lastname + '.'
The second item here asks for first, second and last names, counts the letters and then tells you how many letters there are in your full name. This works, as does the other script above, but I can't help wondering if there isn't a better way to do this.
puts 'What\'s your first name?'
firstname = gets.chomp
puts 'What\'s your second name?'
secondname = gets.chomp
puts 'What\'s your last name?'
lastname = gets.chomp
fullname = firstname.length.to_i + secondname.length.to_i + lastname.length.to_i
puts 'Your name has ' + fullname.to_s + ' letters!'
As you can see and as I have already said, I am a newbie when it comes both to programming and to Ruby. I'd appreciate any help, understanding where I am and accepting that. Also, if you are familiar with another programming language and would like to show how the two programs above would look in that language, feel free to do so in the comments as well.







