Explore Ruby's Methods & Enumerables
Lesson Objectives
During this lesson, students will be:
- Use the ruby docs to find methods
- Use and explain ruby methods
This morning you will each get a Ruby method to explore. Your job is to look in the Ruby documentation to read about the method, come up with an explanation of what it is, and show an example of it in use.
You'll have 15 minutes to research and prepare. You will then take turns sharing your screen and presenting your findings to the class. When you are not presenting, it's your job to listen, learn, take notes, and ask questions.
rstrip/rstrip!reverse/reverse!gsub/gsub!capitalizecapitalize!/upcase/upcase!downcase/downcase!/swapcase/swapcase!chomp/chomp!to_f/to_ito_str/to_sym/to_a
Example string: "we researched ruby methods"
compact/compact!delete_at/delete_iffetchflatten/flatten!samplezip<<first/laststep(note, you'll be doing the.stepon a range of numbers, but it can then be used with an array)joinreduce
Example array:
students = ["An", "Todd", "Mark", "Jim", "Cathleen", "Ky", "Biren", "Geraldine", "Hanna", "Dylan", "Sheila", "Charles", "Soniya", "Jerrica", "Ellen", "Lenin", "Adam", "Stanley", "Matthew", "Anthony", "Joe", "Emily", "Amanda"]has_key?keysmerge/merge!flatteninvert
Example hash:
cohort = {name: "Hopper", instructors: 4, "never_gonna_give_you_up" => "favorite song", most_played_song: "Freebird", instructors: ["Matt", "Thom", "Karolin", "Kristyn"], 100 => 200}odd?/even?floor/nexttimes
Example integers:
1
28
12_345_678- Default values in parameters
Enumerables
The Enumerable module provides a set of methods to traverse, search, sort and manipulate collections
- for in
- each do
- each with index
- map
select/select!
Post your notes and example in Slack
When it's your turn to present, post your topic, notes, and comment in Slack so that others can put it into their notes.
Make sure your notes include at least one code example.
Formatting for Slack:

Example
