Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Ruby makes heavy use of blocks in the built in types and the standard library. In this video, we explore Strings and Integers.
Documentation Links
Code Samples
String#each_char:
string = "Treehouse"
string.each_char{|c| print "#{c}-"}
This prints out:
"T-r-e-e-h-o-u-s-e"
String#each_line:
haiku = <<-EOF
A string with three lines
Is considered multi line
Ruby code haiku
EOF
haiku.each_line{ |line| puts "* #{line}" }
Prints the following:
* A string with three lines
* Is considered multi line
* Ruby code haiku
Integer#down_to:
5.downto(3) { |number| print number }
Prints out the following:
543
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up