Skip to content

kayathewriter/programming-univbasics-3-ruby-method-arguments-lab-online-web-prework

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby Method Arguments Lab

Learning Goals

  • Define a method that takes in and uses an argument
  • Define a method that takes in and uses two arguments
  • Define a method with an optional argument

Introduction

Now that we've seen a few ways of defining methods to add key functionality to our programs, let's try writing our own methods. You can use the tests to help guide you by running learn or learn test in your terminal, however, this look familiar to you now.

You'll be coding your methods in lib/introduction.rb.

Define a Method That Takes in and Uses an Argument

Define a method, #introduction that takes in the argument name and outputs the phrase: "Hi, my name is #{name}."

Define a Method That Takes in and Uses Two Arguments

Define a method, #introduction_with_language that takes in two arguments, name and language and outputs the phrase: "Hi, my name is #{name} and I am learning to program in #{language}."

Define a Method With an Optional Argument

Copy the previous method and name it #introduction_with_language_optional. It that takes in two arguments,name and language, but language is optional. The default value for language will be "Ruby".

Conclusion

We've talked about defining methods and passing in both required and optional arguments. This will be the foundation of creating a lot of functionality in Ruby.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%