Ruby Introduction
Goals
- Use the repl.it interface comfortably
- Identify different between
puts
andprint
- Explore, then explain what String methods can help us do
Review what we know, puts vs. print
Using the repl.it we just forked, complete the activity that follows:
Try It: Exploring puts vs. print
Read the Ruby code in the repl.it and predict what will happen when it is run. With the concepts and vocabulary you learned in the prework, try to explain why! Be ready to share out.
Now, run the repl.it.
Last, change both instances of puts
to print
. Observe the change in output. What does that tell you about the job that each command has?
String Methods
In the spirit of exploring to learn, we aren’t gong to tell what what exactly the code below does - not yet.
first_name = "osCAr"
puts "Hello, #{first_name}!"
puts "Hello, #{first_name.capitalize}!"
Try It: Exploring Methods
Read the code above and predict what will happen when it is run. Try to explain why.
Now, type or copy and paste the code into your repl.it and run it - does that verify or falsify your prediction?
Then, change capitalize
to upcase
, then downcase
, then reverse
. Re-run the code each time to change it, and observe the output.